﻿###########################################
#
#  Business is Contagious
#
#  Made for Nokia 3310 Jam 2, 2020
#  the theme was "Death is Good".
#
###########################################

:alias t0 v4
:alias t1 v5
:alias t2 v6

:const WIDTH  84
:const HEIGHT 48
:const TOP     8
:const LEFT   22
:calc  BOTTOM { TOP  + HEIGHT }
:calc  RIGHT  { LEFT + WIDTH  }

# in XO-Chip we want to lay out all our graphics data
# in high RAM, and reserve low RAM for code.
# these macros allow us to interleave building up
# each segment of the program:

:calc CODE_POS { 0x200  }
:calc DATA_POS { 0x1000 }
:macro to-code { :calc DATA_POS { HERE }  :org { CODE_POS } }
:macro to-data { :calc CODE_POS { HERE }  :org { DATA_POS } }

# Some general-purpose utility macros:

:macro unpack16 ADDR {
	:calc hi { 0xFF & ADDR >> 8 }  v0 := hi
	:calc lo { 0xFF & ADDR      }  v1 := lo
}
:macro unpack32 A B {
	:calc hi-a { 0xFF & A >> 8 }  v0 := hi-a
	:calc lo-a { 0xFF & A      }  v1 := lo-a
	:calc hi-b { 0xFF & B >> 8 }  v2 := hi-b
	:calc lo-b { 0xFF & B      }  v3 := lo-b
}
:macro pointer ADDR {
	:byte { 0xFF & ADDR >> 8 }
	:byte { 0xFF & ADDR      }
}
:macro indirect LABEL {
	0xF0 0x00 : LABEL 0x00 0x00 # i := long NNNN
}
:macro sync SPEED {
	# SPEED is the number of 1/60ths of a second
	# to delay between each repaint:
	loop
		vf := delay
		if vf != 0 then
	again
	vf := SPEED
	delay := vf
}

: random-upto-v1
	loop
		v0 := random 0xF
		if v0 > v1 then
	again
;
: shuffle-base  indirect shuffle-base-slot ;
: shuffle-array
	i := shuffle-base-slot
	save v1
	loop
		v1 := v4
		random-upto-v1
		v3 := v0
		if v3 != v4 begin
			# swap a[v4] / a[v3]...
			shuffle-base
			i += v3
			load v1 - v1 # has a[v3]
			shuffle-base
			i += v4
			load v2 - v2 # has a[v4]
			save v1 - v1
			shuffle-base
			i += v3
			save v2 - v2
		end
		v4 += -1
		if v4 != 2 then
	again
;
:macro shuffle LEN ADDR {
	:calc maxindex { LEN - 1 }
	v4 := maxindex
	unpack16 ADDR
	shuffle-array
}

to-data

# to limit the display resolution, we'll use the second
# graphics plane to create a mask overlay which obscures
# the extra border space. This provides clipping for free
# and makes scrolling graphics much simpler:

: nokia-border
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00
	0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00
	0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00
	0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00
	0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00
	0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00 0xFC 0x00
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F
	0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F
	0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F
	0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F
	0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F
	0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x3F
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

: blit-stash
	0x00 0x00 0x00 0x00 0x00

to-code

:macro nokia-init {
	hires
	plane 2
	i  := long nokia-border
	v2 := 32
	loop
		sprite v0 v1 0
		i  += v2
		v1 += 16
		if v1 ==  64 then v0 += 16
		if v1 ==  64 then v1 := 0
		if v0 != 128 then
	again
	plane 1
}

:macro nokia-impl-blit {
	i := long blit-stash
	save v4
	indirect nokia-blit-dest
	v0 := TOP
	:calc temp1 { 16 + TOP } v1 := temp1
	:calc temp2 { 32 + TOP } v2 := temp2
	v3 := LEFT
	v4 := 32 # stride
	clear
	loop
		sprite v3 v0 0  i += v4
		sprite v3 v1 0  i += v4
		sprite v3 v2 0  i += v4
		v3 += 16
		:calc temp3 { LEFT + 6 * 16 }
		if v3 != temp3 then
	again
	i := long blit-stash
	load v4
}

: dialog-pause
	# debounced key input, to prevent
	# missing out on dialog.
	vf := OCTO_KEY_E
	loop if vf  key then again # wait for release,
	loop if vf -key then again # wait for press,
	loop if vf  key then again # wait for release...
	# ...plus a minimum time delay (fallthrough)
: wait
	vf := 20
	delay := vf
	loop
		vf := delay
		if vf != 0 then
	again
;

###########################################
#
#  World Model
#
###########################################

to-data

: title-docks       0xFE 0x28 0x1C 0x13 0x21 0x1E 0xF9 0x03 0x28 0x1C 0x24 0x2C 0xFF
: title-east        0xFE 0x2B 0x1C 0x04 0x1A 0x2C 0x2D 0xF9 0x12 0x22 0x1D 0x1E 0xFF
: title-wall        0xFE 0x2C 0x1C 0x13 0x21 0x1E 0xF9 0x16 0x1A 0x25 0x25 0xFF 
: title-university  0xFE 0x1B 0x1C 0x14 0x27 0x22 0x2F 0x1E 0x2B 0x2C 0x22 0x2D 0x32 0xF9 0x0F 0x1A 0x2B 0x24 0xFF 
: title-broadway    0xFE 0x28 0x1C 0x01 0x2B 0x28 0x1A 0x1D 0x30 0x1A 0x32 0xFF 
: title-west        0xFE 0x2A 0x1C 0x16 0x1E 0x2C 0x2D 0xF9 0x12 0x22 0x1D 0x1E 0xFF 
: title-core        0xFE 0x2A 0x1C 0x02 0x22 0x2D 0x32 0xF9 0x02 0x28 0x2B 0x1E 0xFF 

: place-title-table
	pointer title-docks
	pointer title-east
	pointer title-wall
	pointer title-university
	pointer title-broadway
	pointer title-west
	pointer title-core

: name-docks       0x13 0x21 0x1E 0xF9 0x03 0x28 0x1C 0x24 0x2C 0xFF 
: name-east        0x04 0x1A 0x2C 0x2D 0xF9 0x12 0x22 0x1D 0x1E 0xFF
: name-wall        0x13 0x21 0x1E 0xF9 0x16 0x1A 0x25 0x25 0xFF
: name-university  0x14 0x27 0x22 0x2F 0x1E 0x2B 0x2C 0x22 0x2D 0x32 0xF9 0x0F 0x1A 0x2B 0x24 0xFF
: name-broadway    0x01 0x2B 0x28 0x1A 0x1D 0x30 0x1A 0x32 0xFF 
: name-west        0x16 0x1E 0x2C 0x2D 0xF9 0x12 0x22 0x1D 0x1E 0xFF 
: name-core        0x02 0x22 0x2D 0x32 0xF9 0x02 0x28 0x2B 0x1E 0xFF 

: place-name-table
	pointer name-docks
	pointer name-east
	pointer name-wall
	pointer name-university
	pointer name-broadway
	pointer name-west
	pointer name-core

: desc-docks # idle dockworkers
	0xFE 0x20 0x0C 0x16 0x28 0x2B 0x24 0x1E 0x2B 0x2C 0xF9 0x22 0x1D 0x25 0x1E 0x41
	0xF9 0xFE 0x21 0x14 0x30 0x22 0x2D 0x21 0xF9 0x27 0x28 0xF9 0x2C 0x21 0x22 0x29
	0x2C 0xF9 0xFE 0x18 0x1C 0x1C 0x28 0x26 0x22 0x27 0x20 0xF9 0x28 0x2B 0xF9 0x20
	0x28 0x22 0x27 0x20 0x3E 0xF9 0xFE 0x19 0x24 0x2D 0x21 0x1E 0xF9 0x2C 0x22 0x25
	0x1E 0x27 0x1C 0x1E 0xF9 0x21 0x1E 0x2B 0x1E 0xF9 0xFE 0x20 0x2C 0x1F 0x1E 0x1E
	0x25 0x2C 0xF9 0x2E 0x27 0x1E 0x1A 0x2C 0x32 0x3E 0xFF 
: desc-east # crowded hospitals
	0xFE 0x1A 0x08 0x13 0x21 0x22 0x2C 0xF9 0x33 0x28 0x27 0x1E 0xF9 0x22 0x2C 0xF9
	0x1F 0x2E 0x25 0x25 0xF9 0xFE 0x23 0x10 0x28 0x1F 0xF9 0x21 0x28 0x2C 0x29 0x22
	0x2D 0x1A 0x25 0x2C 0x41 0xF9 0xFE 0x1A 0x18 0x29 0x1A 0x1C 0x24 0x1E 0x1D 0xF9
	0x30 0x22 0x2D 0x21 0xF9 0x2D 0x21 0x1E 0xF9 0xFE 0x17 0x20 0x2C 0x22 0x1C 0x24
	0x3E 0xF9 0x00 0x26 0x1B 0x2E 0x25 0x1A 0x27 0x1C 0x1E 0x2C 0xF9 0xFE 0x19 0x28
	0x30 0x1A 0x22 0x25 0xF9 0x2C 0x28 0x26 0x1E 0x30 0x21 0x1E 0x2B 0x1E 0xF9 0xFE
	0x18 0x30 0x22 0x27 0xF9 0x2D 0x21 0x1E 0xF9 0x1D 0x22 0x2C 0x2D 0x1A 0x27 0x1C
	0x1E 0x3E 0x3E 0x3E 0xFF 
: desc-wall # FEMA camp
	0xFE 0x19 0x0C 0x05 0x04 0x0C 0x00 0xF9 0x21 0x1A 0x2C 0xF9 0x2C 0x1E 0x2D 0xF9
	0x2E 0x29 0xF9 0xFE 0x22 0x14 0x1A 0xF9 0x1B 0x1A 0x2C 0x1E 0xF9 0x21 0x1E 0x2B
	0x1E 0x3E 0xF9 0xFE 0x22 0x1C 0x16 0x28 0x2B 0x24 0x1E 0x2B 0x2C 0xF9 0x1A 0x2B
	0x1E 0xF9 0xFE 0x1B 0x24 0x21 0x1A 0x27 0x1D 0x22 0x27 0x20 0xF9 0x28 0x2E 0x2D
	0xF9 0x1A 0x22 0x1D 0xF9 0xFE 0x21 0x2C 0x1A 0x27 0x1D 0xF9 0x2C 0x2E 0x29 0x29
	0x25 0x22 0x1E 0x2C 0x3E 0xFF 
: desc-university # research labs
	0xFE 0x1C 0x0C 0x0C 0x1A 0x27 0x32 0xF9 0x2B 0x1E 0x2C 0x1E 0x1A 0x2B 0x1C 0x21
	0xF9 0xFE 0x18 0x14 0x25 0x1A 0x1B 0x2C 0xF9 0x25 0x22 0x1E 0xF9 0x1A 0x1D 0x23
	0x1A 0x1C 0x1E 0x27 0x2D 0xF9 0xFE 0x24 0x1C 0x2D 0x28 0xF9 0x2D 0x21 0x1E 0xF9
	0x29 0x1A 0x2B 0x24 0x3E 0xF9 0xFE 0x1F 0x24 0x0F 0x1E 0x2B 0x21 0x1A 0x29 0x2C
	0x41 0xF9 0x30 0x22 0x2D 0x21 0xF9 0xFE 0x18 0x2C 0x26 0x32 0xF9 0x1C 0x2B 0x1E
	0x1D 0x1E 0x27 0x2D 0x22 0x1A 0x25 0x2C 0x3E 0x3E 0x3E 0xFF 
: desc-broadway # homeless
	0xFE 0x1F 0x0C 0x13 0x21 0x1E 0xF9 0x21 0x28 0x26 0x1E 0x25 0x1E 0x2C 0x2C 0xF9
	0xFE 0x20 0x14 0x20 0x1A 0x2D 0x21 0x1E 0x2B 0xF9 0x21 0x1E 0x2B 0x1E 0x3E 0xF9
	0xF9 0xFE 0x1E 0x1C 0x12 0x21 0x28 0x2E 0x2D 0x22 0x27 0x20 0xF9 0x1A 0x27 0x1D
	0xF9 0xF9 0xFE 0x18 0x24 0x1C 0x28 0x2E 0x20 0x21 0x22 0x27 0x20 0xF9 0x1E 0x1C
	0x21 0x28 0x1E 0x2C 0xF9 0xF9 0xFE 0x1E 0x2C 0x22 0x27 0xF9 0x2D 0x21 0x1E 0xF9
	0x2C 0x2D 0x2B 0x1E 0x1E 0x2D 0x2C 0x3E 0xFF 
: desc-west # open air markets
	0xFE 0x1B 0x0C 0x12 0x1E 0x1E 0x1D 0x32 0xF9 0x28 0x29 0x1E 0x27 0x43 0x1A 0x22
	0x2B 0xF9 0xFE 0x18 0x14 0x26 0x1A 0x2B 0x24 0x1E 0x2D 0x2C 0xF9 0x1F 0x22 0x25
	0x25 0xF9 0x30 0x22 0x2D 0x21 0xF9 0xFE 0x19 0x1C 0x1E 0x1A 0x20 0x1E 0x2B 0xF9
	0x2C 0x21 0x28 0x29 0x29 0x1E 0x2B 0x2C 0x3E 0xF9 0xFE 0x23 0x24 0x18 0x28 0x2E
	0xF9 0x1C 0x1A 0x27 0xF9 0x1B 0x2E 0x32 0xF9 0xFE 0x1A 0x2C 0x1A 0x27 0x32 0x2D
	0x21 0x22 0x27 0x20 0xF9 0x21 0x1E 0x2B 0x1E 0x3E 0x3E 0x3E 0xFF 
: desc-core # business
	0xFE 0x1D 0x0C 0x01 0x1A 0x27 0x24 0x2C 0x41 0xF9 0x28 0x1F 0x1F 0x22 0x1C 0x1E
	0x2C 0x41 0xF9 0xFE 0x26 0x14 0x2C 0x25 0x22 0x1C 0x24 0xF9 0x20 0x25 0x1A 0x2C
	0x2C 0x41 0xF9 0xFE 0x22 0x1C 0x2C 0x2D 0x1E 0x1E 0x25 0xF9 0x1F 0x2B 0x1A 0x26
	0x1E 0x2C 0xF9 0xFE 0x29 0x24 0x1A 0x27 0x1D 0xF9 0x2C 0x2E 0x22 0x2D 0x2C 0x3E
	0xF9 0xFE 0x1F 0x2C 0x09 0x2E 0x2C 0x2D 0xF9 0x01 0x2E 0x2C 0x22 0x27 0x1E 0x2C
	0x2C 0x3E 0xFF 

: place-desc-table
	pointer desc-docks
	pointer desc-east
	pointer desc-wall
	pointer desc-university
	pointer desc-broadway
	pointer desc-west
	pointer desc-core

: place-adj-table # 3 indices per entry
	5 6 1 # 0
	0 6 2 # 1
	1 6 3 # 2
	2 6 4 # 3
	3 2 6 # 4
	4 6 0 # 5
	2 0 4 # 6

:const ITEM_TYPES 8
: item-masks        0x0C 0x1A 0x2C 0x24 0x2C 0xFF
: item-handwipes    0x07 0x1A 0x27 0x1D 0x30 0x22 0x29 0x1E 0x2C 0xFF 
: item-vitamins     0x15 0x22 0x2D 0x1A 0x26 0x22 0x27 0x2C 0xFF
: item-antibiotics  0x00 0x27 0x2D 0x22 0x1B 0x22 0x28 0x2D 0x22 0x1C 0x2C 0xFF
: item-antivirals   0x00 0x27 0x2D 0x22 0x2F 0x22 0x2B 0x1A 0x25 0x2C 0xFF
: item-vaccines     0x15 0x1A 0x1C 0x1C 0x22 0x27 0x1E 0x2C 0xFF
: item-painkillers  0x0F 0x1A 0x22 0x27 0x24 0x22 0x25 0x25 0x1E 0x2B 0x2C 0xFF
: item-bullets      0x01 0x2E 0x25 0x25 0x1E 0x2D 0x2C 0xFF

: item-name-table
	pointer item-masks
	pointer item-handwipes
	pointer item-vitamins
	pointer item-antibiotics
	pointer item-antivirals
	pointer item-vaccines
	pointer item-painkillers
	pointer item-bullets

: level-verylow   0xFE 0x1A 0x28 0x30 0x22 0x25 0x25 0xF9 0x1B 0x1E 0xF9 0x2F 0x1E 0x2B 0x32 0xF9 0x25 0x28 0x30 0xFF 
: level-low       0xFE 0x27 0x28 0x30 0x22 0x25 0x25 0xF9 0x1B 0x1E 0xF9 0x25 0x28 0x30 0xFF 
: level-medium    0xFE 0x1C 0x28 0x30 0x22 0x25 0x25 0xF9 0x1B 0x1E 0xF9 0x26 0x1E 0x1D 0x22 0x2E 0x26 0xFF
: level-high      0xFE 0x25 0x28 0x30 0x22 0x25 0x25 0xF9 0x1B 0x1E 0xF9 0x21 0x22 0x20 0x21 0xFF 
: level-veryhigh  0xFE 0x18 0x28 0x30 0x22 0x25 0x25 0xF9 0x1B 0x1E 0xF9 0x2F 0x1E 0x2B 0x32 0xF9 0x21 0x22 0x20 0x21 0xFF

: level-name-table
	pointer level-verylow
	pointer level-low
	pointer level-medium
	pointer level-high
	pointer level-veryhigh

: item-prices # [v.low, low, medium, high, v.high]
	 1  2  3  5   8 # masks
	 2  3  5 10  15 # handwipes
	 5  9 10 12  20 # vitamins
	10 15 18 24  45 # antibiotics
	23 34 50 70 100 # antivirals
	29 39 50 73 120 # vaccines
	34 38 40 80 135 # painkillers
	30 30 30 30  30 # bullets

:const ZONE_COUNT 7
:const MAX_DAMAGE 3
: STARTING_CASH  0 0  0 0 0  5 0 0

# mutable state follows:

:const EVENT_NEWS   0
:const EVENT_UNLOCK 1
:const EVENT_ARMS   2
:const EVENT_MUGGED 3
:const EVENT_REWARD 4
:const EVENT_NONE   5

: event-queue
	: events-A  0 0 1 2 2  3 3 3 4 5  5 5 5 5 5
	: events-B  0 0 1 2 2  3 3 3 3 3  4 5 5 5 5
	: events-C  0 0 1 2 2  3 3 3 3 3  3 4 5 5 5

: curr-demands
	2 2 2 2 2 2 2 2 # loc 0
	2 2 2 2 2 2 2 2 # loc 1
	2 2 2 2 2 2 2 2 # loc 2
	2 2 2 2 2 2 2 2 # loc 3
	2 2 2 2 2 2 2 2 # loc 4
	2 2 2 2 2 2 2 2 # loc 5
	2 2 2 2 2 2 2 2 # loc 6
: next-demands
	2 2 2 2 2 2 2 2 # loc 0
	2 2 2 2 2 2 2 2 # loc 1
	2 2 2 2 2 2 2 2 # loc 2
	2 2 2 2 2 2 2 2 # loc 3
	2 2 2 2 2 2 2 2 # loc 4
	2 2 2 2 2 2 2 2 # loc 5
	2 2 2 2 2 2 2 2 # loc 6	

: player-status
	: item-owned       0 0 0 0 0 0 0 0
	: place-shown-desc 0 0 0 0 0 0 0 0
	: item-unlocked    1 1 1 1 0 0 0 0
	: game-day        0
	: game-zone       0 # 0...6
	: player-injury   0 # 0...3
	: event-index     0 # 0...45
	: news-index      0 # 0...6
	: unlock-index    0 # 0...3
	: has-gun         0 # 0/1
	: has-loan        0 # 0/1
	: loan-timer      0

:monitor item-owned    8
:monitor item-unlocked 8

: liar-zone 2
: PLAYER_CASH  0 0  0 0 0  0 0 0

to-code

: fill # v0=value, v1=count
	loop
		save v0
		v1 += -1
		if v1 == 0 then return
	again
:macro fill-region BASE LEN VALUE {
	i  := long BASE
	v0 := VALUE
	v1 := LEN
	fill
}

:macro init-world {
	fill-region curr-demands  112 2
	fill-region player-status  33 0
	fill-region item-unlocked   4 1

	v0 := random 0b111 # maybe no liar?
	i := long liar-zone
	save v0

	copy STARTING_CASH PLAYER_CASH

	# by dividing events into three arenas,
	# we exert some control to ensure that
	# certain event types don't get clumped
	# together too much:
	shuffle 15 events-A
	shuffle 15 events-B
	shuffle 15 events-C
}

###########################################
#
#  Text rendering routines
#
#  These generic routines can draw pre-wrapped
#  bytecoded strings with 2 inlineable text
#  fragment slots, as created by EZ-Writer:
#
#  http://beyondloom.com/tools/ezwriter.html
#
#  Pointers are "passed" to these routines
#  by rewriting immediate i-loads,
#  and macros help make the process more compact.
#
#  Note that fragments should NOT contain STR_POS
#  or recursive fragment references!
#
###########################################

:const STR_END    0xFF
:const STR_POS    0xFE
:const STR_SLOT_0 0xFB
:const STR_SLOT_1 0xFA
:const STR_SPACE  0xF9

:alias fragment-offset v3
:alias string-offset   v4
:alias cursor-x        v5
:alias cursor-y        v6

: print-char
	if v0 == STR_POS begin
		string-offset += 2
		cursor-x := v1
		cursor-y := v2
		return
	end
	if v0 == STR_SPACE begin
		cursor-x += 3
		return
	end
	if v0 == STR_SLOT_0 begin
		fragment-offset := 0
		loop
			indirect print-string0-read
			i += fragment-offset
			load v0
			if v0 == STR_END then return
			fragment-offset += 1
			print-char
		again
	end
	if v0 == STR_SLOT_1 begin
		fragment-offset := 0
		loop
			indirect print-string1-read
			i += fragment-offset
			load v0
			if v0 == STR_END then return
			fragment-offset += 1
			print-char
		again
	end
	# draw a plain character
	i  := long nokia-font
	i  += v0 # add v0 * 9
	v0 += v0
	i  += v0
	i  += v0
	i  += v0
	i  += v0
	sprite cursor-x cursor-y 8

	# add horizontal width
	vf := 8
	i  += vf
	load vf - vf
	cursor-x += vf
;

: print-text-xy
	i := print-string-read
	save v1
	i := long string-stash
	save vf
	string-offset := 0
	jump print-text-body
: print-text
	i := print-string-read
	save v1
	i := long string-stash
	save vf
	string-offset := 0
	cursor-x      := LEFT
	cursor-y      := TOP
: print-text-body
	loop
		indirect print-string-read
		i += string-offset
		load v2
		while v0 != STR_END
		string-offset += 1
		print-char
	again
	i := long string-stash
	load vf
;

:macro print ADDR { unpack16 ADDR print-text }

to-data

# the Nokia font is comprised of 8x8 characters,
# and each is followed by a width in pixels:

: nokia-font
	0x70 0xD8 0xD8 0xD8 0xF8 0xD8 0xD8 0x00 0x06 # A
	0xF0 0xD8 0xF0 0xD8 0xD8 0xD8 0xF0 0x00 0x06 # B
	0x78 0xC0 0xC0 0xC0 0xC0 0xC0 0x78 0x00 0x06 # C
	0xF0 0xD8 0xD8 0xD8 0xD8 0xD8 0xF0 0x00 0x06 # D
	0xF8 0xC0 0xF0 0xC0 0xC0 0xC0 0xF8 0x00 0x06 # E
	0xF8 0xC0 0xF0 0xC0 0xC0 0xC0 0xC0 0x00 0x06 # F
	0x70 0xC0 0xC0 0xD8 0xD8 0xD8 0x78 0x00 0x06 # G
	0xD8 0xD8 0xF8 0xD8 0xD8 0xD8 0xD8 0x00 0x06 # H
	0xC0 0xC0 0xC0 0xC0 0xC0 0xC0 0xC0 0x00 0x03 # I
	0x30 0x30 0x30 0x30 0x30 0x30 0xE0 0x00 0x05 # J
	0xCC 0xD8 0xF0 0xE0 0xF0 0xD8 0xCC 0x00 0x07 # K
	0xC0 0xC0 0xC0 0xC0 0xC0 0xC0 0xF0 0x00 0x05 # L
	0x82 0xC6 0xEE 0xFE 0xD6 0xC6 0xC6 0x00 0x08 # M
	0x8C 0xCC 0xEC 0xFC 0xDC 0xCC 0xC4 0x00 0x07 # N
	0x78 0xCC 0xCC 0xCC 0xCC 0xCC 0x78 0x00 0x07 # O
	0xF0 0xD8 0xD8 0xD8 0xF0 0xC0 0xC0 0x00 0x06 # P
	0x78 0xCC 0xCC 0xCC 0xCC 0xDC 0x78 0x0C 0x07 # Q
	0xF0 0xD8 0xD8 0xD8 0xF0 0xD0 0xD8 0x00 0x06 # R
	0x70 0xC0 0xC0 0x60 0x30 0x30 0xE0 0x00 0x05 # S
	0xFC 0x30 0x30 0x30 0x30 0x30 0x30 0x00 0x07 # T
	0xD8 0xD8 0xD8 0xD8 0xD8 0xD8 0x70 0x00 0x06 # U
	0xCC 0xCC 0xCC 0x78 0x78 0x30 0x30 0x00 0x07 # V
	0xC6 0xC6 0xC6 0xD6 0x7C 0x7C 0x6C 0x00 0x08 # W
	0xCC 0xCC 0x78 0x30 0x78 0xCC 0xCC 0x00 0x07 # X
	0xCC 0xCC 0x78 0x30 0x30 0x30 0x30 0x00 0x07 # Y
	0xF8 0x18 0x38 0x70 0xE0 0xC0 0xF8 0x00 0x06 # Z
	0x00 0x00 0x70 0x18 0x78 0xD8 0x78 0x00 0x06 # a
	0xC0 0xC0 0xF0 0xD8 0xD8 0xD8 0xF0 0x00 0x06 # b
	0x00 0x00 0x70 0xC0 0xC0 0xC0 0x70 0x00 0x05 # c
	0x18 0x18 0x78 0xD8 0xD8 0xD8 0x78 0x00 0x06 # d
	0x00 0x00 0x70 0xD8 0xF8 0xC0 0x78 0x00 0x06 # e
	0x60 0xC0 0xE0 0xC0 0xC0 0xC0 0xC0 0x00 0x04 # f
	0x00 0x00 0x78 0xD8 0xD8 0x78 0x18 0x70 0x06 # g
	0xC0 0xC0 0xF0 0xD8 0xD8 0xD8 0xD8 0x00 0x06 # h
	0xC0 0x00 0xC0 0xC0 0xC0 0xC0 0xC0 0x00 0x03 # i
	0x60 0x00 0x60 0x60 0x60 0x60 0x60 0xC0 0x04 # j
	0xC0 0xC0 0xD8 0xF0 0xE0 0xF0 0xD8 0x00 0x06 # k
	0xC0 0xC0 0xC0 0xC0 0xC0 0xC0 0xC0 0x00 0x03 # l
	0x00 0x00 0xFE 0xDB 0xDB 0xDB 0xDB 0x00 0x09 # m
	0x00 0x00 0xF0 0xD8 0xD8 0xD8 0xD8 0x00 0x06 # n
	0x00 0x00 0x70 0xD8 0xD8 0xD8 0x70 0x00 0x06 # o
	0x00 0x00 0xF0 0xD8 0xD8 0xF0 0xC0 0xC0 0x06 # p
	0x00 0x00 0x78 0xD8 0xD8 0x78 0x18 0x18 0x06 # q
	0x00 0x00 0xD0 0xF0 0xC0 0xC0 0xC0 0x00 0x05 # r
	0x00 0x00 0x70 0xC0 0xF0 0x30 0xE0 0x00 0x05 # s
	0xC0 0xC0 0xE0 0xC0 0xC0 0xC0 0x60 0x00 0x04 # t
	0x00 0x00 0xD8 0xD8 0xD8 0xD8 0x78 0x00 0x06 # u
	0x00 0x00 0xD8 0xD8 0x70 0x70 0x20 0x00 0x06 # v
	0x00 0x00 0xC6 0xD6 0xD6 0x7C 0x6C 0x00 0x08 # w
: nokia-x
	0x00 0x00 0xD8 0xD8 0x70 0xD8 0xD8 0x00 0x06 # x
	0x00 0x00 0xD8 0xD8 0xD8 0x78 0x18 0x70 0x06 # y
	0x00 0x00 0xF8 0x30 0x60 0xC0 0xF8 0x00 0x06 # z
: nokia-digits
	0x70 0xD8 0xD8 0xD8 0xD8 0xD8 0x70 0x00 0x06 # 0
	0x60 0xE0 0x60 0x60 0x60 0x60 0x60 0x00 0x04 # 1
	0xF0 0x18 0x18 0x70 0xC0 0xC0 0xF8 0x00 0x06 # 2
	0xF0 0x18 0x18 0x70 0x18 0x18 0xF0 0x00 0x06 # 3
	0x18 0x38 0x58 0x98 0xF8 0x18 0x18 0x00 0x06 # 4
	0xF0 0x80 0xF0 0x18 0x18 0x18 0xF0 0x00 0x06 # 5
	0x70 0xC0 0xF0 0xD8 0xD8 0xD8 0x70 0x00 0x06 # 6
	0xF8 0x18 0x30 0x30 0x60 0x60 0x60 0x00 0x06 # 7
	0x70 0xD8 0xD8 0x70 0xD8 0xD8 0x70 0x00 0x06 # 8
	0x70 0xD8 0xD8 0xD8 0x78 0x18 0x70 0x00 0x06 # 9
	0x00 0x00 0x00 0x00 0x00 0xC0 0xC0 0x00 0x03 # .
	0xC0 0xC0 0xC0 0xC0 0xC0 0x00 0xC0 0x00 0x03 # !
	0xF0 0x18 0x30 0x60 0x60 0x00 0x60 0x00 0x06 # ?
	0x00 0x00 0x00 0x00 0x00 0x40 0xC0 0x80 0x03 # ,
	0x80 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x02 # '
	0x00 0x00 0x00 0xF0 0x00 0x00 0x00 0x00 0x05 # -
	0xA0 0xA0 0x00 0x00 0x00 0x00 0x00 0x00 0x04 # "
: nokia-dollar
	0x50 0x78 0xD0 0xF0 0x78 0x58 0xF0 0x50

: string-stash
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

###########################################
#
#  Big Math
#
#  For representing money, we need numbers
#  larger than will fit in a byte. These
#  routines provide 8-digit integers.
#
#  all of these destroy v0-v3.
#
###########################################

: BIG_DECODE  0 0  0 0 0  : BIG_DECODE_TARGET  0 0 0
: BIG_DECODE2 0 0  0 0 0  : BIG_DECODE_TARGET2 0 0 0
: BIG_ZERO    0 0  0 0 0  0 0 0
: BIG_TEMP    0 0  0 0 0  0 0 0

to-code

:alias n-carry v2
:alias n-index v3

:const BIG_DIGITS 8
: n-a indirect n-a-addr i += n-index ;
: n-b indirect n-b-addr i += n-index ;

: n-args
	i := n-a-addr save v0 - v1
	i := n-b-addr save v2 - v3
;

: n-copy-pointers
	n-args
: n-copy # b := a
	n-index := 0
	loop
		n-a load v0
		n-b save v0
		n-index += 1
		if n-index != BIG_DIGITS then
	again
;

: n-more-pointers
	n-args
: n-more # ve := (b >= a)
	n-index := 0
	ve := 0
	loop
		n-a load v0
		n-b load v1 - v1
		if v0 >  v1 then return
		if v0 != v1 then jump n-more-success
		n-index += 1
		if n-index != BIG_DIGITS then
	again
: n-more-success
	ve := 1
;

: n-add-pointers
	n-args
: n-add # b += a
	n-carry := 0
	n-index := BIG_DIGITS
	loop
		n-index += -1
		n-a load v0
		n-b load v1 - v1
		v0 += v1
		v0 += n-carry
		n-carry := 0
		if v0 > 9 begin
			n-carry := 1
			v0 += -10
		end
		n-b save v0
		if n-index != 0 then
	again
;

: n-sub-pointers
	n-args
: n-sub # b -= a
	n-carry := 0
	n-index := BIG_DIGITS
	loop
		n-index += -1
		n-a load v0
		n-b load v1 - v1
		v0 += n-carry
		n-carry := 0
		if v0 > v1 begin
			v1 += 10
			n-carry := 1
		end
		v1 -= v0
		n-b save v1 - v1
		if n-index != 0 then
	again
;

:macro decode REG { i := long BIG_DECODE_TARGET bcd REG }
:macro decode2 REG { i := long BIG_DECODE_TARGET2 bcd REG }
:macro copy A B { unpack32 A B n-copy-pointers }
:macro more A B { unpack32 A B n-more-pointers }
:macro add  A B { unpack32 A B n-add-pointers  }
:macro sub  A B { unpack32 A B n-sub-pointers  }

###########################################
#
#  Number rendering
#
###########################################

to-data

: number-stash
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
: small-dollar
	0x20 0xF8 0xA0 0xF8 0x28 0xF8 0x20

to-code

:alias number-index v3
:alias number-empty v4

: number-read indirect number-src i += number-index ;
: number-pre
	i := number-src
	save v1
	i := long number-stash
	save vf

	# count empty leading digits
	number-index := 0
	number-empty := 0
	loop
		number-read load v0
		while v0 == 0
		while number-index != BIG_DIGITS
		number-empty += 1
		number-index += 1
	again
	if number-empty == BIG_DIGITS then number-empty += -1
;
: number-body
	# draw characters backwards from cursor-x
	number-index := BIG_DIGITS
	loop
		number-index += -1
		number-read load v0
		i := long nokia-digits
		i  += v0 # add v0 * 9
		v0 += v0
		i  += v0
		i  += v0
		i  += v0
		i  += v0
		load vf - v7 # v7 now has char width
		cursor-x -= v7
		sprite cursor-x cursor-y 8
		if number-index != number-empty then
	again
;

: number-nokia
	number-pre
	number-body
	jump number-post
: currency-nokia
	number-pre
	number-body
	cursor-x += -6
	i := long nokia-dollar
	sprite cursor-x	cursor-y 8
	jump number-post
: count-nokia
	number-pre
	number-body
	cursor-x += -6
	i := long nokia-x
	sprite cursor-x	cursor-y 8
: number-post
	i := long number-stash
	load vf
;

: number-chip8
	number-pre
	# draw characters backwards from cursor-x
	number-index := BIG_DIGITS
	loop
		number-index += -1
		number-read load v0
		i := hex v0
		cursor-x += -5
		sprite cursor-x cursor-y 5
		if number-index != number-empty then
	again
	cursor-x += -6
	cursor-y += -1
	i := long small-dollar
	sprite cursor-x cursor-y 7
	jump number-post

###########################################
#
#  Scripting Engine
#
#  glue together sequences of string drawing,
#  dialog pauses and so on, to conserve
#  chewing up precious code space.
#
###########################################

:const SCRIPT_CLEAR  0
:const SCRIPT_PRINT  1
:const SCRIPT_PAUSE  2
:const SCRIPT_BLIT   3
:const SCRIPT_INC    4
:const SCRIPT_DEC    5
:const SCRIPT_RANDOM 6
:const SCRIPT_ITEMS  7
:const SCRIPT_END   -1

: script-load
	i := script-ptr-load
	save v1 - v2
	v3 += 2
	indirect script-ptr-load
;
: script-from-table-t2
	i += t2
	i += t2
	load v1
: script-exec
	i := script-body
	save v1
	v3 := 0 # script program counter...
	loop
		indirect script-body
		i  += v3
		v3 += 1
		load v2
		if v0 == SCRIPT_END   then return
		if v0 == SCRIPT_CLEAR then clear
		if v0 == SCRIPT_PAUSE begin
			dialog-pause
			clear
		end
		if v0 == SCRIPT_BLIT begin
			i := nokia-blit-dest
			save v1 - v2
			v3 += 2
			nokia-impl-blit
		end
		if v0 == SCRIPT_INC begin
			script-load
			load v1 - v1
			v1 += 1
			save v1 - v1
		end
		if v0 == SCRIPT_DEC begin
			script-load
			load v1 - v1
			v1 += -1
			save v1 - v1
		end
		if v0 == SCRIPT_RANDOM begin
			script-load
			vf := random 0b1110
			i += vf
			load v1
			jump script-exec
		end
		if v0 == SCRIPT_ITEMS begin
			loop
				vf := random 0b111
				if vf == 7 then # no bullets!
			again
			i := long item-owned
			i += vf
			load v2 - v2
			v1 := random 31
			v1 += 5
			v2 += v1
			if v2 > 200 then v2 := 200
			save v2 - v2
		end
		if v0 == SCRIPT_PRINT begin
			v0 := v1
			v1 := v2
			v3 += 2
			print-text
		end
	again

:macro s-clear       { :byte SCRIPT_CLEAR }
:macro s-pause       { :byte SCRIPT_PAUSE }
:macro s-end         { :byte SCRIPT_END }
:macro s-items       { :byte SCRIPT_ITEMS }
:macro s-print  ADDR { :byte SCRIPT_PRINT  pointer ADDR }
:macro s-blit   ADDR { :byte SCRIPT_BLIT   pointer ADDR }
:macro s-inc    ADDR { :byte SCRIPT_INC    pointer ADDR }
:macro s-dec    ADDR { :byte SCRIPT_DEC    pointer ADDR }
:macro s-random ADDR { :byte SCRIPT_RANDOM pointer ADDR }
:macro script   ADDR { unpack16 ADDR script-exec }

###########################################
#
#  Menus
#
#  Designed to resemble the OS menus
#  on the Nokia 3310
#
###########################################

to-data

: scroll-bars # 16x32 each
	0xE0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0x00 0x00 0x00 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xA0 0x00 0xA0 0x00
	0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0x00 0x00 0x00 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00
	0xA0 0x00 0xA0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0x00 0x00 0x00 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0x00 0x00 0x00 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00
	0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xE0 0x00 0xA0 0x00
	0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xA0 0x00 0xE0 0x00 0x00 0x00 0x00 0x00

: scroll-bar-table # which index maps to which sprite?
	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # count 0 (n/a)
	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # count 1 (n/a)
	0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # count 2
	0 2 4 0 0 0 0 0 0 0 0 0 0 0 0 0 # count 3
	0 1 3 4 0 0 0 0 0 0 0 0 0 0 0 0 # count 4
	0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 # count 5
	0 1 1 3 3 4 0 0 0 0 0 0 0 0 0 0 # count 6
	0 1 1 2 3 3 4 0 0 0 0 0 0 0 0 0 # count 7
	0 1 1 2 2 3 3 4 0 0 0 0 0 0 0 0 # count 8
	0 1 1 2 2 2 3 3 4 0 0 0 0 0 0 0 # count 9
	0 1 1 1 2 2 3 3 3 4 0 0 0 0 0 0 # count 10
	0 1 1 1 2 2 2 3 3 3 4 0 0 0 0 0 # count 11
	0 1 1 1 1 2 2 3 3 3 3 4 0 0 0 0 # count 12
	0 1 1 1 1 2 2 2 3 3 3 3 4 0 0 0 # count 13
	0 1 1 1 1 2 2 2 2 3 3 3 3 4 0 0 # count 14
	0 1 1 1 1 2 2 2 2 2 3 3 3 3 4 0 # count 15

: text-highlight # 8x10
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
: text-highlight-end # 6x10
	0xFC 0xFC 0xFC 0xFC 0xFC 0xFC 0xFC 0xFC 0xFC 0xFC

: menu-strings # 16 pointer slots
	0x00 0x00  0x00 0x00  0x00 0x00  0x00 0x00
	0x00 0x00  0x00 0x00  0x00 0x00  0x00 0x00
	0x00 0x00  0x00 0x00  0x00 0x00  0x00 0x00
	0x00 0x00  0x00 0x00  0x00 0x00  0x00 0x00
: menu-nums # 16 number slots (-1 is don't show)
	0 0 0 0  0 0 0 0  0 0 0 0  0 0 0 0
: menu-keys # 16 key slots
	0 0 0 0  0 0 0 0  0 0 0 0  0 0 0 0
: menu-verb-slot # 1 pointer slot
	0x00 0x00

: verb-ok     0xFE 0x3A 0x2F 0x0E 0x0A 0xFF
: verb-sell   0xFE 0x38 0x2F 0x12 0x1E 0x25 0x25 0xFF
: verb-buy    0xFE 0x38 0x2F 0x01 0x2E 0x32 0xFF
: verb-travel 0xFE 0x30 0x2F 0x13 0x2B 0x1A 0x2F 0x1E 0x25 0xFF

: batteries
	0xFE 0xFF 0xFF 0xFF 0xFE # 0
	0xFE 0xFB 0xF9 0xFB 0xFE # 1
	0xFE 0xE3 0xE1 0xE3 0xFE # 2
	0xFE 0x83 0x81 0x83 0xFE # >=3

: homescreen-0
	0x00 0x00 0x78 0x00 0x78 0x00 0x78 0x00 0x78 0x00 0x78 0x00 0x78 0x00 0x78 0x00
	0x00 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00
	0x00 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00
	0x00 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00
	0x00 0x00 0x7C 0x00 0x54 0x00 0x38 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0xFF
	0x00 0x7F 0x00 0x1E 0x00 0x00 0x00 0x3F 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x0F 0x00 0x30 0xC0 0x40 0x20 0x80 0x10 0x80 0x10 0x40 0x20 0x00 0x00 0xFF 0xFF
	0x80 0x1F 0x00 0x06 0x00 0xF8 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0xC0 0x01 0xE0 0x1F 0x70 0x3F 0x80 0x76 0xE0 0x65 0x70
	0x6D 0xB0 0x1C 0xC0 0x1C 0xA0 0x18 0x70 0x00 0x50 0x07 0xB8 0x18 0x28 0xE0 0x28
	0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x07 0x80 0xE7 0x80 0xE7 0x80 0xE7 0x80 0xE7 0x80 0xE7 0x80 0xE7 0x80 0xE0 0x00
	0x07 0x00 0xE7 0x00 0xE7 0x00 0xE7 0x00 0xE7 0x00 0xE7 0x00 0xE7 0x00 0xE0 0x00
	0x06 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x60 0x00
	0x06 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x60 0x00
	0x07 0xC0 0xC5 0x40 0xE3 0x80 0x21 0x00 0x21 0x00 0x21 0x00 0xE0 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
: homescreen-1
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x70 0x00
	0x00 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00
	0x00 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00
	0x00 0x00 0x7C 0x00 0x54 0x00 0x38 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0xFF
	0x00 0x7F 0x00 0x1F 0x00 0x00 0x00 0x3F 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x0F 0x00 0x30 0xC0 0x40 0x20 0x80 0x10 0x00 0x00 0xFF 0xFF
	0x80 0x1F 0x00 0x0E 0x00 0xF8 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0xC0 0x01 0xE0 0x1F 0x70 0x3F 0x80 0x76 0xE0 0x65 0x70
	0x6D 0xB0 0x1C 0xC0 0x1C 0xA0 0x18 0x70 0x00 0x50 0x07 0xB8 0x18 0x28 0xE0 0x28
	0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x07 0x00 0x07 0x00 0x07 0x00 0x07 0x00 0x07 0x00 0x07 0x00 0x07 0x00 0x00 0x00
	0x06 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x60 0x00
	0x06 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x60 0x00
	0x07 0xC0 0xC5 0x40 0xE3 0x80 0x21 0x00 0x21 0x00 0x21 0x00 0xE0 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00	
: homescreen-2
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00
	0x00 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00 0x60 0x00
	0x00 0x00 0x7C 0x00 0x54 0x00 0x38 0x00 0x10 0x00 0x10 0x00 0x10 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0xFF
	0x00 0x7F 0x00 0x1F 0x00 0x00 0x00 0x3F 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x40
	0x00 0x00 0x00 0x00 0x00 0x00 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80
	0x00 0x04 0x00 0x00 0x00 0x00 0x00 0x00 0x0F 0x00 0x30 0xC0 0x00 0x00 0xFF 0xFF
	0xE0 0x7F 0x80 0x1E 0x00 0xF8 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x40 0xC0 0x01 0xE0 0x1F 0x70 0x3F 0x80 0x76 0xE0 0x65 0x70
	0x6D 0xB0 0x1C 0xC0 0x1C 0xA0 0x18 0x70 0x00 0x50 0x07 0xB8 0x18 0x28 0xE0 0x28
	0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x06 0x00 0x06 0x00 0x06 0x00 0x06 0x00 0x06 0x00 0x06 0x00 0x06 0x00 0x00 0x00
	0x06 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x66 0x00 0x60 0x00
	0x07 0xC0 0xC5 0x40 0xE3 0x80 0x21 0x00 0x21 0x00 0x21 0x00 0xE0 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

: day-screen 0xFE 0x30 0x2A 0x03 0x1A 0x32 0xF9 0xFF # y=42
: gun-sprite
	0x5F 0xFC 0x3F 0xFE 0x3F 0xFC 0x7F 0xFC 0x79 0x00 0xFE 0x00 0xF0 0x00 0x70 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

: script-homescreen-0
	s-clear
	s-blit homescreen-0
	s-print day-screen
	s-end
: script-homescreen-1
	s-clear
	s-blit homescreen-1
	s-print day-screen
	s-end
: script-homescreen-2
	s-clear
	s-blit homescreen-2
	s-print day-screen
	s-end

: homescreen-table
	pointer script-homescreen-0
	pointer script-homescreen-1
	pointer script-homescreen-2
	pointer script-homescreen-2 # padding for safety (not used)
	pointer script-homescreen-2 # padding for safety (not used)

:macro show-homescreen {
	i := long player-injury
	load t2 - t2
	i := long homescreen-table
	script-from-table-t2
	i := long has-gun
	load v0
	v1 := 29
	v2 := 10
	i := long gun-sprite
	if v0 != 0 then sprite v1 v2 0
	cursor-x := 80
	cursor-y := 42
	decode-day
}

to-code

:alias menu-index v7
:alias menu-top   v8
:alias menu-count v9

: menu-set-verb # pointer in [v0,v1]
	i := long menu-verb-slot
	save v0 - v1
;
:macro menu-verb ADDR { unpack16 ADDR menu-set-verb }
: menu-clear
	menu-verb verb-ok
	menu-index := 0
	menu-top   := 0
	menu-count := 0
	vf         := -1
	vd         := 0 # show dollar signs?
;
: menu-add-body # pointer in [v0,v1], key in ve, quantity in vf
	i := long menu-strings
	i += menu-count
	i += menu-count
	save v0 - v1
	i := long menu-keys
	i += menu-count
	save ve - ve
	i := long menu-nums
	i += menu-count
	save vf - vf
	menu-count += 1
;
:macro menu-add  KEY ADDR { unpack16 ADDR ve := KEY menu-add-body }

: menu-draw-confirm
	v0 := 44
	v1 := 46
	i  := long text-highlight
	loop
		sprite v0 v1 9
		v0 += 8
		if v0 != 84 then
	again
;
: menu-draw-cash
	print-text
	cursor-x := 104
	cursor-y := 9
	unpack16 PLAYER_CASH number-chip8
;

:macro menu-draw {
	clear

	# draw verb
	i := long menu-verb-slot
	load v1
	menu-draw-cash

	# battery indicator
	v0 := 24
	v1 := 9
	i  := long player-injury
	load v2 - v2
	if v2 > 3 then v2 := 3
	i  := long batteries
	i  +=  v2
	v2 <<= v2
	v2 <<= v2
	i  +=  v2
	sprite v0 v1 5

	# draw scroll bars
	v0 := menu-count
	v1 := 16
	i := long scroll-bar-table
	loop
		while v0 != 0
		i  += v1
		v0 += -1
	again
	i += menu-index
	load v0
	i  := long scroll-bars
	v1 := 64
	loop
		while v0 != 0
		i  += v1
		v0 += -1
	again
	v0 := 102
	v2 := 15
	sprite v0 v2 0
	v1 := 32
	i  += v1
	v2 += 16
	sprite v0 v2 0

	# draw 3 menu items
	v2 := menu-top
	v3 := v2
	v3 += 3
	cursor-y := 16
	loop
		cursor-x := 24
		while v2 != menu-count
		while v2 != v3
		i := long menu-strings
		i += v2
		i += v2
		load v1
		print-text-xy

		# annotate menu with number,
		# when desired:
		i := long menu-nums
		i += v2
		load v0
		if v0 != -1 begin
			cursor-x := 100
			decode v0
			unpack16 BIG_DECODE
			if vd == 1 begin
				currency-nokia
			else
				count-nokia
			end
		end

		v2 += 1
		cursor-y += 10
	again

	# draw highlight
	v0 := menu-index
	v0 -= menu-top
	v1 := 0
	loop
		while v0 != 0
		v1 += 10
		v0 += -1
	again
	v1 += 15
	v0 := 23
	i  := long text-highlight
	loop
		sprite v0 v1 10
		v0 += 8
		if v0 != 95 then
	again
	i  := long text-highlight-end
	sprite v0 v1 10
}

: menu # return result key in t0
	loop
		menu-draw
		v0 := key
		if v0 == OCTO_KEY_W begin
			if menu-index == 0 begin
				# wrap up top
				menu-index := menu-count
				menu-index += -1
				menu-top   := menu-index
				if menu-top != 0 then menu-top += -1
				if menu-top != 0 then menu-top += -1
			else
				menu-index += -1
			end
			# shift top up
			if menu-index < menu-top then menu-top := menu-index
		end
		if v0 == OCTO_KEY_S begin
			v1 := menu-count
			v1 += -1
			if menu-index == v1 begin
				# wrap down bottom
				menu-top   := 0
				menu-index := 0
			else
				menu-index += 1
			end
			# shift top down
			v1 := menu-top
			v1 += 3
			if menu-index == v1 then menu-top += 1
		end
		if v0 == OCTO_KEY_E begin
			menu-draw-confirm
			wait
			menu-draw-confirm
			i := long menu-keys
			i += menu-index
			load t0 - t0
			return
		end
	again

: quantity-draw-total
	cursor-x := 98
	cursor-y := 34
	unpack16 BIG_TEMP
	currency-nokia

	cursor-x := 53
	decode2 vb
	unpack16 BIG_DECODE2
	count-nokia
;

:macro quantity-draw {
	clear
	i := long item-name-table
	i += t0
	i += t0
	load v1
	cursor-x := 32
	cursor-y := 20
	print-text-xy
	quantity-draw-total
	unpack16 verb-buy
	menu-draw-cash
}

: quantity # t0 contains item to draw...
	t0-item-price
	decode vf              # BIG_DECODE has unit price
	vB := 0                # number to buy
	copy BIG_ZERO BIG_TEMP # total price
	quantity-draw

	loop
		sync 5
		vf := OCTO_KEY_E
		while vf -key

		vf := OCTO_KEY_W
		if vf key begin
			quantity-draw-total

			vB += 1
			add BIG_DECODE BIG_TEMP

			# ensure player has enough cash
			more BIG_TEMP PLAYER_CASH # ve := (b >= a)
			if ve == 0 begin
				vB += -1
				sub BIG_DECODE BIG_TEMP
			end
			# ensure player has enough inventory space
			i := long item-owned
			i += t0
			load v0 - v0
			v0 += vB
			if v0 > 200 begin
				vB += -1
				sub BIG_DECODE BIG_TEMP
			end

			quantity-draw-total
		end

		vf := OCTO_KEY_S
		if vf key begin
			if vB != 0 begin
				quantity-draw-total
				vB += -1
				sub BIG_DECODE BIG_TEMP
				quantity-draw-total
			end
		end
	again

	menu-draw-confirm
	vf := OCTO_KEY_E
	loop while vf key again
	menu-draw-confirm

	sub BIG_TEMP PLAYER_CASH
	i := long item-owned
	i += t0
	load v0 - v0
	v0 += vB
	save v0 - v0
;

###########################################
#
#  Economy
#
###########################################

to-data

: econ-stash 0 0 0 0  0 0 0 0  0 0 0 0  0 0 0 0

to-code

: demand-addr # v0 zone (destructive)
	i  := long next-demands
	v0 += v0
	v0 += v0
	v0 += v0
	i  += v0 # zone * 8
;

:macro churn-economy {
	i := long econ-stash
	save vf
	
	# copy next-demands (8 * 7 bytes) to curr-demands
	ve := 0
	vd := 0
	loop
		i := long next-demands
		i += vd
		load v7
		i := long curr-demands
		i += vd
		save v7
		ve += 1
		vd += 8
		if ve != ZONE_COUNT then
	again

	# perform some random demand transfers
	v2 := 15
	loop
		v1 := 6
		random-upto-v1
		va := v0 # random zone source
		random-upto-v1
		vb := v0 # random zone dest

		vc := random 0b111 # random commodity source
		vd := random 0b111 # random commodity dest

		:macro demand-at ZONE ITEM { v0 := ZONE demand-addr i += ITEM }

		demand-at va vc
		load t0 - t0 # source demand...
		if t0 == 0 then jump transfer-bailout

		demand-at vb vd
		load t1 - t1 # dest demand...
		if t1 == 4 then jump transfer-bailout

		demand-at va vc
		t0 += -1 # remove from source...
		save t0 - t0 

		demand-at vb vd
		t1 += 1 # add to dest...
		save t1 - t1

		: transfer-bailout
		v2 += -1
		if v2 != 0 then
	again

	i := long econ-stash
	load vf
}

:monitor next-demands 56
:monitor curr-demands 56

: t0-item-price # to vf
	i := long game-zone
	load vf - vf # current zone
	i := long curr-demands
	i += vf # i + ( vf * 8 )
	i += vf
	i += vf
	i += vf
	i += vf
	i += vf
	i += vf
	i += vf
	i += t0
	load vf - vf # demand of item in zone
	i := long item-prices
	i += t0 # i + ( t0 * 5 )
	i += t0
	i += t0
	i += t0
	i += t0
	i += vf
	load vf - vf # price of item given demand
;

###########################################
#
#  Tips
#
###########################################

to-data

: BIG_TIP_COST 0 0  0 0 0  0 0 3

: tip-buzz-off
	0xFE 0x16 0x14 0xFE 0x1E 0x14 0x44 0x01 0x2E 0x33 0x33 0xF9 0x28 0x1F 0x1F 0x41
	0xF9 0x29 0x1A 0x25 0x3E 0xFE 0x19 0x1C 0x18 0x28 0x2E 0xF9 0x1C 0x1A 0x27 0x42
	0x2D 0xF9 0x1A 0x1F 0x1F 0x28 0x2B 0x1D 0xFE 0x25 0x24 0x26 0x32 0xF9 0x29 0x2B
	0x22 0x1C 0x1E 0x2C 0x3E 0x44 0xFF
: script-buzz-off
	s-clear
	s-print tip-buzz-off
	s-pause
	s-end

: tip-price # three bucks...
	0xFE 0x17 0x14 0x44 0x07 0x28 0x2D 0xF9 0x26 0x1A 0x2B 0x24 0x1E 0x2D 0xF9 0x2D
	0x22 0x29 0x2C 0x41 0xF9 0xFE 0x21 0x1C 0x28 0x27 0x25 0x32 0xF9 0x37 0xF9 0x1B
	0x2E 0x1C 0x24 0x2C 0x3E 0xF9 0xFE 0x18 0x24 0x08 0x27 0x2D 0x1E 0x2B 0x1E 0x2C
	0x2D 0x1E 0x1D 0x41 0xF9 0x29 0x1A 0x25 0x40 0x44 0xFF 
: script-tip-price
	s-clear
	s-print tip-price
	s-pause
	s-end

: tip-another
	0xFE 0x1B 0x18 0x44 0x16 0x28 0x2E 0x25 0x1D 0xF9 0x32 0x28 0x2E 0xF9 0x25 0x22
	0x24 0x1E 0xF9 0xFE 0x1A 0x20 0x2D 0x28 0xF9 0x24 0x27 0x28 0x30 0xF9 0x26 0x28
	0x2B 0x1E 0x40 0x44 0xFF
: script-tip-another
	s-clear
	s-print tip-another
	s-pause
	s-end

: str-buytip    0x01 0x2E 0x32 0xF9 0x2D 0x22 0x29 0xFF
: str-nothanks  0x0D 0x28 0xF9 0x2D 0x21 0x1A 0x27 0x24 0x2C 0xFF
: str-demandfor 0xFE 0x1A 0x10 0x03 0x1E 0x26 0x1A 0x27 0x1D 0xF9 0x1F 0x28 0x2B 0xF9 0xF9 0xFE
	            0x1A 0x18 0xFB 0xF9 0x1A 0x2D 0xF9 0xF9 0xFE 0x1A 0x20 0xFA 0xFF
to-code

: handle-tips
	# insufficient cash
	more BIG_TIP_COST PLAYER_CASH # ve := (b >= a)
	if ve == 0 begin
		script script-buzz-off
		jump misc-actions
	end
	script script-tip-price
	loop
		menu-clear
		menu-add 1 str-buytip
		menu-add 0 str-nothanks
		menu

		if t0 == 0 then jump misc-actions
		sub BIG_TIP_COST PLAYER_CASH

		# come up with a tip
		v1 := 6
		random-upto-v1
		va := v0 # tip zone
		loop
			vb := random 0b111 # tip item
			i := long item-unlocked
			i += vb
			load v1 - v1
			if v1 == 0 then
		again
		demand-addr
		i += vb
		load vc - vc # tip demand

		# handle liars
		i := long liar-zone
		load v0 - v0
		i := long game-zone
		load v1 - v1
		if v0 == v1 begin
			v1 := 4
			random-upto-v1
			vc := v0
		end

		# display that sucker
		i := long level-name-table
		i += vc
		i += vc
		load v1
		clear
		print-text
		i := long item-name-table
		i += vb
		i += vb
		load v1
		i := long print-string0-read
		save v1
		i := long place-name-table
		i += va
		i += va
		load v1
		i := long print-string1-read
		save v1
		print str-demandfor
		dialog-pause

		more BIG_TIP_COST PLAYER_CASH
		if ve == 0 then jump misc-actions
		script script-tip-another
	again

###########################################
#
#  Game Over
#
###########################################

to-data

: end-scores    0xFE 0x1E 0x14 0x03 0x1A 0x32 0x2C 0xF9 0xFE 0x1E 0x24 0x0F 0x2B 0x28 0x1F 0x22 0x2D 0xFF 
: end-screen    0xFE 0x2B 0x1C 0x13 0x21 0x1E 0xF9 0x04 0x27 0x1D 0x3E 0xFF 

: script-the-end
	s-clear
	s-print end-screen
	s-pause
	s-clear
	s-print end-scores
	s-end

to-code

: decode-day
	i := long game-day
	load v0 - v0
	v0 += 1 # BE CAREFUL! THIS ROUTINE INCREMENTS, TOO!
	save v0 - v0
	decode v0
	unpack16 BIG_DECODE
	number-nokia
;

###########################################
#
#  Escape
#
###########################################

to-data

: BIG_ESCAPE_COST 0 0  0 0 2  5 0 0

: str-imready   0x08 0x42 0x26 0xF9 0x2B 0x1E 0x1A 0x1D 0x32 0x3E 0xFF
: str-nevermind 0x0D 0x1E 0x2F 0x1E 0x2B 0xF9 0x26 0x22 0x27 0x1D 0x3E 0x3E 0x3E 0xFF

: desc-abandoned-1
	0xFE 0x1B 0x10 0x13 0x21 0x1E 0xF9 0x1B 0x28 0x1A 0x2D 0x26 0x1A 0x27 0xF9 0x22
	0x2C 0xF9 0xFE 0x1D 0x18 0x27 0x28 0x30 0x21 0x1E 0x2B 0x1E 0xF9 0x2D 0x28 0xF9
	0x1B 0x1E 0xF9 0xFE 0x31 0x20 0x1F 0x28 0x2E 0x27 0x1D 0x3F 0xF9 0xFE 0x2D 0x28
	0x03 0x1A 0x26 0x27 0xF9 0x22 0x2D 0x3F 0xFF	
: desc-abandoned-2
	0xFE 0x18 0x10 0x08 0x42 0x26 0xF9 0x2D 0x2B 0x1A 0x29 0x29 0x1E 0x1D 0xF9 0x21
	0x1E 0x2B 0x1E 0xF9 0xFE 0x19 0x18 0x30 0x22 0x2D 0x21 0xF9 0x2D 0x21 0x1E 0xF9
	0x29 0x25 0x1A 0x20 0x2E 0x1E 0x3E 0xF9 0xFE 0x26 0x20 0x0D 0x28 0xF9 0x1E 0x2C
	0x1C 0x1A 0x29 0x1E 0x3E 0xF9 0xFE 0x19 0x28 0x0C 0x32 0xF9 0x21 0x1E 0x1A 0x1D
	0xF9 0x2D 0x21 0x2B 0x28 0x1B 0x2C 0x3E 0xFF
: desc-abandoned-3
	0xFE 0x18 0x14 0x08 0xF9 0x1B 0x1E 0x20 0x22 0x27 0xF9 0x2D 0x28 0xF9 0x1C 0x28
	0x2E 0x20 0x21 0x41 0xF9 0xFE 0x1F 0x1C 0x1A 0x27 0x1D 0xF9 0x26 0x32 0xF9 0x2F
	0x22 0x2C 0x22 0x28 0x27 0xF9 0xFE 0x1E 0x24 0x2C 0x25 0x28 0x30 0x25 0x32 0xF9
	0x1F 0x1A 0x1D 0x1E 0x2C 0x3E 0x3E 0x3E 0xFF 
: desc-escape-intro
	0xFE 0x20 0x14 0x13 0x21 0x1E 0xF9 0x1B 0x28 0x1A 0x2D 0x26 0x1A 0x27 0xF9 0xFE
	0x1B 0x1C 0x22 0x2C 0xF9 0x2B 0x1E 0x1A 0x1D 0x32 0xF9 0x1F 0x28 0x2B 0xF9 0x26
	0x1E 0xF9 0xFE 0x21 0x24 0x1A 0x2D 0xF9 0x2D 0x21 0x1E 0xF9 0x1D 0x28 0x1C 0x24
	0x2C 0x3E 0xFF 
: desc-escape-cannot-pay
	0xFE 0x1E 0x0C 0x44 0x13 0x21 0x1E 0xF9 0x1D 0x1E 0x1A 0x25 0xF9 0x30 0x1A 0x2C
	0xF9 0xFE 0x1C 0x14 0x36 0x39 0x34 0x34 0xF9 0x2D 0x28 0xF9 0x20 0x1E 0x2D 0xF9
	0x28 0x1F 0x1F 0xF9 0xFE 0x2A 0x1C 0x2D 0x21 0x22 0x2C 0xF9 0x2B 0x28 0x1C 0x24
	0x3E 0xF9 0xFE 0x18 0x24 0x02 0x28 0x26 0x1E 0xF9 0x1B 0x1A 0x1C 0x24 0xF9 0x30
	0x21 0x1E 0x27 0xF9 0xFE 0x20 0x2C 0x32 0x28 0x2E 0xF9 0x1C 0x1A 0x27 0xF9 0x29
	0x1A 0x32 0x3E 0x44 0xFF
: desc-escape-confirm
	0xFE 0x1D 0x10 0x44 0x05 0x22 0x27 0x22 0x2C 0x21 0x1E 0x1D 0xF9 0x30 0x22 0x2D
	0x21 0xF9 0xFE 0x16 0x18 0x1A 0x25 0x25 0xF9 0x32 0x28 0x2E 0x2B 0xF9 0x1B 0x2E
	0x2C 0x22 0x27 0x1E 0x2C 0x2C 0xF9 0xFE 0x1A 0x20 0x21 0x1E 0x2B 0x1E 0x41 0xF9
	0x21 0x1A 0x2F 0x1E 0xF9 0x32 0x1E 0x40 0xF9 0xFE 0x1D 0x28 0x0B 0x1E 0x2D 0xF9
	0x2E 0x2C 0xF9 0x1D 0x1E 0x29 0x1A 0x2B 0x2D 0x3E 0x44 0xFF 
: desc-escape-finish
	0xFE 0x1C 0x10 0x14 0x27 0x1D 0x1E 0x2B 0xF9 0x1C 0x28 0x2F 0x1E 0x2B 0xF9 0x28
	0x1F 0xF9 0xFE 0x1F 0x18 0x1D 0x1A 0x2B 0x24 0x27 0x1E 0x2C 0x2C 0x41 0xF9 0x28
	0x2E 0x2B 0xF9 0xFE 0x1B 0x20 0x1B 0x28 0x1A 0x2D 0xF9 0x2C 0x25 0x22 0x29 0x2C
	0xF9 0x1A 0x30 0x1A 0x32 0xF9 0xFE 0x1B 0x28 0x22 0x27 0x2D 0x28 0xF9 0x2D 0x21
	0x1E 0xF9 0x27 0x22 0x20 0x21 0x2D 0x3E 0x3E 0x3E 0xFF

: script-abandoned
	s-clear
	s-print desc-abandoned-1
	s-pause
	s-clear
	s-print desc-abandoned-2
	s-pause
	s-clear
	s-print desc-abandoned-3
	s-pause
	s-end
: script-escape-intro
	s-clear
	s-print desc-escape-intro
	s-pause
	s-end
: script-escape-cannot-pay
	s-clear
	s-print desc-escape-cannot-pay
	s-pause
	s-end
: script-escape-confirm
	s-clear
	s-print desc-escape-confirm
	s-pause
	s-end
: script-escape-finish
	s-clear
	s-print desc-escape-finish
	s-pause
	s-end

: desc-death-1
	0xFE 0x24 0x0C 0x0C 0x32 0xF9 0x2C 0x2D 0x28 0x26 0x1A 0x1C 0x21 0xF9 0xFE 0x1D
	0x14 0x1C 0x21 0x2E 0x2B 0x27 0x2C 0x3E 0xF9 0x08 0xF9 0x2B 0x1E 0x2D 0x1C 0x21
	0xF9 0xFE 0x1F 0x1C 0x1A 0x27 0x1D 0xF9 0x1F 0x1A 0x25 0x25 0xF9 0x2D 0x28 0xF9
	0x26 0x32 0xF9 0xFE 0x1B 0x24 0x24 0x27 0x1E 0x1E 0x2C 0x3E 0xF9 0x0C 0x32 0xF9
	0x21 0x1E 0x1A 0x1D 0xF9 0xFE 0x20 0x2C 0x22 0x2C 0xF9 0x29 0x28 0x2E 0x27 0x1D
	0x22 0x27 0x20 0x3E 0x3E 0x3E 0xFF
: desc-death-2
	0xFE 0x24 0x0C 0x08 0xF9 0x1C 0x1A 0x27 0xF9 0x1B 0x1A 0x2B 0x1E 0x25 0x32 0xF9
	0xFE 0x20 0x14 0x1B 0x2B 0x1E 0x1A 0x2D 0x21 0x1E 0xF9 0x1A 0x26 0x22 0x1D 0xF9
	0xFE 0x20 0x1C 0x26 0x32 0xF9 0x1C 0x28 0x2E 0x20 0x21 0x22 0x27 0x20 0x3E 0xF9
	0xFE 0x36 0x24 0x0D 0x28 0x3E 0x3E 0x3E 0xF9 0xFE 0x1F 0x2C 0x0D 0x28 0x2D 0xF9
	0x25 0x22 0x24 0x1E 0xF9 0x2D 0x21 0x22 0x2C 0x3E 0x3E 0x3E 0xFF

: script-death-injury
	s-clear
	s-print desc-death-1
	s-pause
	s-clear
	s-print desc-death-2
	s-pause
	s-end

to-code

: handle-escape
	i := long news-index
	load v0
	if v0 == 6 begin
		script script-abandoned
		jump game-over
	end

	script script-escape-intro

	more BIG_ESCAPE_COST PLAYER_CASH # ve := (b >= a)
	if ve == 0 begin
		script script-escape-cannot-pay
		jump misc-actions
	end

	script script-escape-confirm
	menu-clear
	menu-add 1 str-imready
	menu-add 0 str-nevermind
	menu
	if t0 == 0 then jump misc-actions

	script script-escape-finish
	sub BIG_ESCAPE_COST PLAYER_CASH
	jump game-over

: death-injury
	script script-death-injury
: game-over
	script script-the-end
	cursor-x := 100
	cursor-y := 20
	decode-day
	cursor-y := 36
	unpack16 PLAYER_CASH
	currency-nokia
	dialog-pause
	jump game-start

###########################################
#
#  Loan Sharks
#
###########################################

to-data

: BIG_LOAN_AMOUNT   0 0  0 0 3  0 0 0
: BIG_LOAN_INTEREST 0 0  0 0 5  0 0 0
:const LOAN_LENGTH 6 # +1...

: desc-loans-intro-1
	0xFE 0x1F 0x10 0x13 0x21 0x22 0x2C 0xF9 0x1B 0x1A 0x27 0x24 0xF9 0x1C 0x1A 0x27
	0xF9 0xFE 0x1F 0x18 0x25 0x1E 0x27 0x1D 0xF9 0x26 0x1E 0xF9 0x2C 0x28 0x26 0x1E
	0xF9 0xFE 0x29 0x20 0x1F 0x1A 0x2C 0x2D 0xF9 0x1C 0x1A 0x2C 0x21 0x41 0xF9 0xFE
	0x22 0x28 0x1F 0x28 0x2B 0xF9 0x1A 0xF9 0x29 0x2B 0x22 0x1C 0x1E 0x3E 0x3E 0x3E
	0xFF
: desc-loans-intro-2
	0xFE 0x17 0x0C 0x44 0x18 0x28 0x2E 0xF9 0x20 0x1E 0x2D 0xF9 0x37 0xF9 0x20 0x2B
	0x1A 0x27 0x1D 0xF9 0xFE 0x19 0x14 0x27 0x28 0x30 0x41 0xF9 0x32 0x28 0x2E 0xF9
	0x29 0x1A 0x32 0xF9 0x2E 0x2C 0xF9 0xFE 0x1B 0x1C 0x1B 0x1A 0x1C 0x24 0xF9 0x39
	0xF9 0x20 0x2B 0x1A 0x27 0x1D 0xF9 0x22 0x27 0xF9 0xFE 0x18 0x24 0x39 0xF9 0x1D
	0x1A 0x32 0x2C 0x3E 0x3E 0x3E 0xF9 0x28 0x2B 0xF9 0x1E 0x25 0x2C 0x1E 0x3E 0xF9
	0xFE 0x31 0x2C 0x03 0x1E 0x1A 0x25 0x40 0x44 0xFF 
: desc-loan-confirm
	0xFE 0x23 0x10 0x44 0x07 0x1E 0x2B 0x1E 0x42 0x2C 0xF9 0x32 0x28 0x2E 0x2B 0xF9
	0xFE 0x1D 0x18 0x1D 0x28 0x2E 0x20 0x21 0x3E 0xF9 0x06 0x1E 0x2D 0xF9 0x28 0x2E
	0x2D 0xF9 0xFE 0x1A 0x20 0x2D 0x21 0x1E 0x2B 0x1E 0xF9 0x1A 0x27 0x1D 0xF9 0x26
	0x1A 0x24 0x1E 0xF9 0xFE 0x17 0x28 0x2C 0x28 0x26 0x1E 0xF9 0x26 0x28 0x2B 0x1E
	0x41 0xF9 0x29 0x1A 0x25 0x3E 0x44 0xFF
: desc-loan-complete
	0xFE 0x1C 0x10 0x44 0x16 0x1E 0x42 0x25 0x25 0xF9 0x2D 0x1A 0x24 0x1E 0xF9 0x2D
	0x21 0x1A 0x2D 0xF9 0xFE 0x1F 0x18 0x39 0xF9 0x20 0x2B 0x1A 0x27 0x1D 0x41 0xF9
	0x27 0x28 0x30 0x3E 0xF9 0xFE 0x1C 0x20 0x0F 0x25 0x1E 0x1A 0x2C 0x2E 0x2B 0x1E
	0xF9 0x1D 0x28 0x22 0x27 0x20 0xF9 0xFE 0x28 0x28 0x1B 0x2E 0x2C 0x22 0x27 0x1E
	0x2C 0x2C 0x3E 0x44 0xFF
: desc-loan-during
	0xFE 0x23 0x10 0x44 0x0D 0x28 0x2D 0xF9 0x1E 0x27 0x28 0x2E 0x20 0x21 0xF9 0xFE
	0x1E 0x18 0x1C 0x1A 0x2C 0x21 0x40 0xF9 0x16 0x1E 0x25 0x25 0xF9 0x20 0x1E 0x2D
	0xF9 0xFE 0x1C 0x20 0x28 0x2E 0x2D 0x2D 0x1A 0xF9 0x21 0x1E 0x2B 0x1E 0xF9 0x1A
	0x27 0x1D 0xF9 0xFE 0x20 0x28 0x1E 0x1A 0x2B 0x27 0xF9 0x22 0x2D 0x41 0xF9 0x1F
	0x1A 0x2C 0x2D 0x3F 0x44 0xFF
: desc-loan-fail-1
	0xFE 0x22 0x0C 0x44 0x02 0x28 0x26 0x22 0x27 0x42 0xF9 0x1B 0x1A 0x1C 0x24 0xF9
	0xFE 0x1E 0x14 0x21 0x1E 0x2B 0x1E 0xF9 0x1A 0x1F 0x2D 0x1E 0x2B 0xF9 0x27 0x28
	0x2D 0xF9 0xFE 0x28 0x1C 0x29 0x1A 0x32 0x22 0x27 0x42 0xF9 0x2E 0x2C 0x40 0xF9
	0xFE 0x18 0x24 0x13 0x21 0x1A 0x2D 0xF9 0x2D 0x1A 0x24 0x1E 0x2C 0xF9 0x2C 0x28
	0x26 0x1E 0xF9 0xFE 0x2F 0x2C 0x1B 0x1A 0x25 0x25 0x2C 0x3E 0x3E 0x3E 0x44 0xFF
: desc-loan-fail-2
	0xFE 0x26 0x10 0x44 0x0D 0x28 0x2D 0xF9 0x26 0x1A 0x27 0x32 0xF9 0xF9 0xFE 0x1A
	0x18 0x1B 0x2B 0x1A 0x22 0x27 0x2C 0x41 0xF9 0x2D 0x21 0x28 0x2E 0x20 0x21 0x3E
	0xF9 0xF9 0xFE 0x20 0x20 0x07 0x1E 0x2B 0x1E 0x41 0xF9 0x25 0x1E 0x26 0x26 0x1E
	0xF9 0xF9 0xFE 0x26 0x28 0x2C 0x21 0x28 0x30 0xF9 0x32 0x1A 0x3E 0x3E 0x3E 0x44
	0xFF

: script-loans-intro
	s-clear
	s-print desc-loans-intro-1
	s-pause
	s-clear
	s-print desc-loans-intro-2
	s-pause
	s-end

: script-loans-confirm
	s-clear
	s-print desc-loan-confirm
	s-pause
	s-inc has-loan
	s-end

: script-loan-complete
	s-clear
	s-print desc-loan-complete
	s-pause
	s-dec has-loan
	s-end

: script-loan-during
	s-clear
	s-print desc-loan-during
	s-pause
	s-end

: script-loan-fail
	s-clear
	s-print desc-loan-fail-1
	s-pause
	s-clear
	s-print desc-loan-fail-2
	s-pause
	s-end

: str-deal   0x03 0x1E 0x1A 0x25 0x3F 0xFF
: str-nodeal 0x0D 0x28 0xF9 0x1D 0x1E 0x1A 0x25 0x3E 0xFF

: desc-loan-goons
	0xFE 0x18 0x0C 0x14 0x21 0x43 0x28 0x21 0x41 0xF9 0x22 0x2D 0x42 0x2C 0xF9 0x20
	0x28 0x28 0x27 0x2C 0xF9 0xFE 0x1A 0x14 0x1F 0x2B 0x28 0x26 0xF9 0x2D 0x21 0x28
	0x2C 0x1E 0xF9 0x25 0x28 0x1A 0x27 0xF9 0xFE 0x2F 0x1C 0x2C 0x21 0x1A 0x2B 0x24
	0x2C 0x3F 0xF9 0xFE 0x2A 0x24 0x06 0x2E 0x1E 0x2C 0x2C 0xF9 0x08 0x42 0x26 0xF9
	0xFE 0x2B 0x2C 0x28 0x2F 0x1E 0x2B 0x1D 0x2E 0x1E 0x3F 0xFF
: script-loan-goons
	s-clear
	s-print desc-loan-goons
	s-pause
	s-end

to-code

: return-loans
	# if you have the cash, just pay it off
	more BIG_LOAN_INTEREST PLAYER_CASH
	if ve != 0 begin
		sub BIG_LOAN_INTEREST PLAYER_CASH
		i := long loan-timer
		v0 := 0
		save v0
		script script-loan-complete
		jump misc-actions
	end
	# if you have enough time, badger the player
	i := long loan-timer
	load v0
	if v0 < LOAN_LENGTH begin
		script script-loan-during
		jump misc-actions
	end
	# otherwise, you're a dead man:
	script script-loan-fail
	jump game-over

: handle-loans
	i := long has-loan
	load v0
	if v0 != 0 then jump return-loans
	script script-loans-intro
	menu-clear
	menu-add 1 str-deal
	menu-add 0 str-nodeal
	menu
	if t0 == 0 then jump misc-actions
	add BIG_LOAN_AMOUNT PLAYER_CASH
	script script-loans-confirm
	jump misc-actions

:macro handle-goons {
	i := long has-loan
	load v0
	if v0 != 0 begin
		i := long loan-timer
		load v0 - v0
		v0 += 1
		save v0 - v0
		if v0 > LOAN_LENGTH begin
			script script-loan-goons
			handle-combat
		end
	end
}

###########################################
#
#  Raiding
#
###########################################

to-data

: str-doraid  0x12 0x2D 0x1A 0x20 0x1E 0xF9 0x2B 0x1A 0x22 0x1D 0xFF 
: str-abort   0x00 0x1B 0x28 0x2B 0x2D 0xF9 0x26 0x22 0x2C 0x2C 0x22 0x28 0x27 0xFF

: desc-warn-markets # easy
	0xFE 0x17 0x0C 0x13 0x21 0x1E 0xF9 0x26 0x1A 0x2B 0x24 0x1E 0x2D 0x2C 0xF9 0x1A
	0x2B 0x1E 0xF9 0xFE 0x1B 0x14 0x1C 0x21 0x1A 0x28 0x2D 0x22 0x1C 0x3E 0xF9 0x0C
	0x1A 0x24 0x22 0x27 0x20 0xF9 0xFE 0x1F 0x1C 0x28 0x1F 0x1F 0xF9 0x30 0x22 0x2D
	0x21 0xF9 0x2C 0x28 0x26 0x1E 0xF9 0xFE 0x21 0x24 0x20 0x28 0x28 0x1D 0x2C 0xF9
	0x2C 0x1E 0x1E 0x26 0x2C 0xF9 0xFE 0x19 0x2C 0x2C 0x22 0x26 0x29 0x25 0x1E 0xF9
	0x1E 0x27 0x28 0x2E 0x20 0x21 0x3E 0x3E 0x3E 0xFF 
: desc-warn-hospital # medium
	0xFE 0x2D 0x0C 0x16 0x22 0x2D 0x21 0xF9 0x26 0x32 0xF9 0xFE 0x24 0x14 0x1C 0x2B
	0x1E 0x1D 0x1E 0x27 0x2D 0x22 0x1A 0x25 0x2C 0x41 0xF9 0xFE 0x1C 0x1C 0x08 0xF9
	0x26 0x22 0x20 0x21 0x2D 0xF9 0x1B 0x1E 0xF9 0x1A 0x1B 0x25 0x1E 0xF9 0xFE 0x27
	0x24 0x2D 0x28 0xF9 0x2C 0x25 0x22 0x29 0xF9 0x22 0x27 0x2D 0x28 0xF9 0xFE 0x24
	0x2C 0x1A 0xF9 0x21 0x28 0x2C 0x29 0x22 0x2D 0x1A 0x25 0x3E 0x3E 0x3E 0xFF
: desc-warn-university # medium
	0xFE 0x1B 0x10 0x13 0x21 0x1E 0xF9 0x2E 0x27 0x22 0x2F 0x1E 0x2B 0x2C 0x22 0x2D
	0x32 0xF9 0xFE 0x18 0x18 0x25 0x1A 0x1B 0x2C 0xF9 0x26 0x22 0x20 0x21 0x2D 0xF9
	0x21 0x1A 0x2F 0x1E 0xF9 0xFE 0x16 0x20 0x2E 0x2C 0x1E 0x1F 0x2E 0x25 0xF9 0x26
	0x1A 0x2D 0x1E 0x2B 0x22 0x1A 0x25 0x2C 0x3E 0xF9 0xFE 0x1D 0x28 0x03 0x28 0xF9
	0x08 0xF9 0x1C 0x21 0x1A 0x27 0x1C 0x1E 0xF9 0x22 0x2D 0x40 0xFF
: desc-warn-fema # hard
	0xFE 0x1A 0x0C 0x13 0x21 0x1E 0xF9 0x05 0x04 0x0C 0x00 0xF9 0x1C 0x1A 0x26 0x29
	0xF9 0xFE 0x19 0x14 0x22 0x2C 0xF9 0x21 0x22 0x20 0x21 0x43 0x2C 0x1E 0x1C 0x2E
	0x2B 0x22 0x2D 0x32 0x41 0xF9 0xFE 0x23 0x1C 0x1B 0x2E 0x2D 0xF9 0x29 0x1E 0x2B
	0x21 0x1A 0x29 0x2C 0xF9 0xFE 0x1F 0x24 0x2D 0x21 0x1E 0x22 0x2B 0xF9 0x2C 0x2E
	0x29 0x29 0x25 0x22 0x1E 0x2C 0xF9 0xFE 0x1F 0x2C 0x1A 0x2B 0x1E 0xF9 0x30 0x28
	0x2B 0x2D 0x21 0xF9 0x22 0x2D 0x3E 0x3E 0x3E 0xFF 

: desc-try-raid-markets
	0xFE 0x22 0x10 0x08 0xF9 0x2D 0x2B 0x32 0xF9 0x2D 0x28 0xF9 0x2C 0x2D 0x1E 0x1A
	0x25 0xF9 0xFE 0x1F 0x18 0x2C 0x28 0x26 0x1E 0xF9 0x26 0x1E 0x1D 0x22 0x1C 0x1A
	0x25 0xF9 0xFE 0x1F 0x20 0x2C 0x2E 0x29 0x29 0x25 0x22 0x1E 0x2C 0xF9 0x1F 0x2B
	0x28 0x26 0xF9 0xFE 0x1E 0x28 0x2D 0x21 0x1E 0xF9 0x26 0x1A 0x2B 0x24 0x1E 0x2D
	0x2C 0x3E 0x3E 0x3E 0xFF 
: desc-try-raid-hospital
	0xFE 0x24 0x10 0x08 0xF9 0x2C 0x25 0x22 0x29 0xF9 0x22 0x27 0x2D 0x28 0xF9 0x1A
	0xF9 0xFE 0x17 0x18 0x21 0x28 0x2C 0x29 0x22 0x2D 0x1A 0x25 0x41 0xF9 0x25 0x28
	0x28 0x24 0x22 0x27 0x20 0xF9 0xFE 0x19 0x20 0x1F 0x28 0x2B 0xF9 0x2C 0x28 0x26
	0x1E 0xF9 0x2E 0x2C 0x1E 0x1F 0x2E 0x25 0xF9 0xFE 0x28 0x28 0x2C 0x2E 0x29 0x29
	0x25 0x22 0x1E 0x2C 0x3E 0x3E 0x3E 0xFF
: desc-try-raid-university
	0xFE 0x18 0x10 0x0F 0x22 0x1C 0x24 0x22 0x27 0x20 0xF9 0x1A 0xF9 0x25 0x28 0x1C
	0x24 0xF9 0x28 0x27 0xF9 0xFE 0x19 0x18 0x1A 0xF9 0x2E 0x27 0x22 0x2F 0x1E 0x2B
	0x2C 0x22 0x2D 0x32 0xF9 0x25 0x1A 0x1B 0x41 0xF9 0xFE 0x1A 0x20 0x08 0xF9 0x2C
	0x1E 0x1A 0x2B 0x1C 0x21 0xF9 0x1F 0x28 0x2B 0xF9 0x1A 0x27 0x32 0xF9 0xFE 0x18
	0x28 0x2E 0x2C 0x1E 0x1F 0x2E 0x25 0xF9 0x2C 0x2E 0x29 0x29 0x25 0x22 0x1E 0x2C
	0x3E 0x3E 0x3E 0xFF
: desc-try-raid-fema
	0xFE 0x1B 0x0C 0x08 0xF9 0x1F 0x25 0x1A 0x2C 0x21 0xF9 0x26 0x32 0xF9 0x08 0x03
	0xF9 0x1A 0x2D 0xF9 0xFE 0x19 0x14 0x2D 0x21 0x1E 0xF9 0x05 0x04 0x0C 0x00 0xF9
	0x1C 0x1A 0x26 0x29 0x3E 0xF9 0xFE 0x1A 0x1C 0x0C 0x2E 0x2C 0x2D 0xF9 0x26 0x28
	0x2F 0x1E 0xF9 0x1F 0x1A 0x2C 0x2D 0xF9 0xFE 0x19 0x24 0x1B 0x1E 0x1F 0x28 0x2B
	0x1E 0xF9 0x2D 0x21 0x1E 0x32 0xF9 0x20 0x1E 0x2D 0xF9 0xFE 0x23 0x2C 0x2C 0x2E
	0x2C 0x29 0x22 0x1C 0x22 0x28 0x2E 0x2C 0x3E 0x3E 0x3E 0xFF

: img-raid-loot
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x03 0x00 0x03 0x00 0x03 0x00 0x03
	0x00 0x01 0x00 0x01 0x00 0x01 0x00 0x01 0xFF 0xFD 0x00 0x05 0xFF 0xFD 0xFF 0xFC
	0xFF 0xFE 0xD8 0xF0 0xFF 0x87 0xFF 0xB8 0xFF 0xB9 0xFF 0xBF 0xFF 0xBF 0xFF 0xDF
	0xFF 0xDF 0xFF 0xDF 0xFF 0xEF 0xFF 0xEF 0xFF 0xF7 0xFF 0xF7 0xFF 0xF7 0xFF 0xFB
	0xFF 0xFB 0xFF 0xFB 0xFF 0xFD 0xFF 0xFD 0xFF 0xF6 0xFF 0xF6 0xFF 0xCB 0xFE 0x7F
	0xFF 0xFD 0xFF 0xF7 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x1F 0xFF 0xE0 0x83 0xFF 0xFC 0x0F 0xFF 0xE0
	0xFF 0xFF 0xFF 0xFE 0xFF 0xFE 0xFF 0xFE 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xE0 0xF0 0x1F 0x0F 0xE0 0xF0 0x00 0x00 0x00 0xE0 0x00 0xF8 0x3F
	0xFF 0xC4 0xFE 0x02 0xFF 0x00 0xFF 0x00 0xFF 0x00 0xFF 0x40 0xFF 0x81 0xFF 0x82
	0xFF 0x80 0xFF 0xF0 0xFF 0xC0 0xFF 0xC0 0xFF 0xE0 0xFF 0xE0 0x7F 0xE0 0x9F 0xF8
	0xEF 0xFC 0xB3 0xF2 0xFD 0xF0 0xFE 0x78 0xFF 0xB9 0xFF 0xCF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0x80 0x00 0x7E 0xFF 0x61 0xFF 0x6E 0x07 0xFF
	0xF8 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x04 0x00 0x08 0x00 0x10 0x00 0x3F 0x00
	0xC4 0xF8 0x3D 0x07 0xC5 0xF8 0x0D 0xFF 0x05 0xFF 0x05 0xFC 0x7E 0x00 0x80 0x00
	0x00 0x00 0x00 0x00 0x00 0x70 0x00 0x70 0x00 0x70 0x00 0x7E 0x03 0xFE 0x03 0xFE
	0x03 0xF0 0x00 0x70 0x00 0x70 0x00 0x70 0x80 0x00 0x40 0x81 0x01 0x00 0x00 0x00
	0x04 0x00 0x0C 0x0F 0x1D 0xFF 0x1F 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xF0 0x00 0x7F 0x00 0x81 0x00
	0x01 0x00 0x01 0x00 0x01 0x07 0x01 0x58 0x02 0xBC 0x02 0xBF 0x02 0x70 0x02 0xF4
	0xFF 0xFF 0xFA 0x7F 0x7F 0x80 0x87 0xC0 0xF8 0xA0 0x00 0xC0 0x00 0xE0 0x00 0xE8
	0x01 0xF0 0x01 0xE0 0x01 0xD0 0x01 0xC0 0x01 0xE9 0x01 0xF0 0x01 0xFA 0x01 0xFD
	0x01 0xFE 0x01 0xFF 0x03 0xFF 0x02 0x00 0x03 0xFE 0x03 0x3F 0x03 0xF7 0x4F 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0xF0 0x00 0x08 0x00 0x05 0xFF 0xC4 0x80 0x32 0xFF 0x0A 0xFF
	0x0A 0xC6 0xE4 0x7F 0x1F 0xBF 0x00 0x5F 0x00 0x2F 0x00 0x17 0x00 0x0F 0x00 0x4B
	0x00 0x4B 0x00 0x4B 0x00 0xDF 0x00 0x5F 0x00 0x9B 0x00 0x93 0x01 0x13 0x21 0xB7
	0x82 0x7F 0xD4 0xEF 0xEB 0x9B 0xFF 0x67 0x0F 0xFE 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x0F 0xFF 0xF0 0x00 0x0F 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFD 0x8F 0xFF 0xF8 0xFF 0xFB 0xFF 0xFB 0xFF 0xFB 0xFF 0xFB 0xFF 0xFD 0xFF 0xFD
	0xFF 0xFD 0xFF 0xFE 0xFF 0xFE 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFC 0xFF 0xE7 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xF0 0x00

: desc-raid-succeed
	0xFE 0x24 0x10 0x08 0xF9 0x26 0x1A 0x27 0x1A 0x20 0x1E 0xF9 0x2D 0x28 0xF9 0xFE
	0x26 0x18 0x2C 0x2D 0x1E 0x1A 0x25 0xF9 0x1A 0xF9 0x1F 0x1E 0x30 0xF9 0xFE 0x26
	0x20 0x1B 0x28 0x31 0x1E 0x2C 0xF9 0x30 0x22 0x2D 0x21 0xF9 0xFE 0x28 0x28 0x2C
	0x2E 0x29 0x29 0x25 0x22 0x1E 0x2C 0x3E 0x3E 0x3E 0xFF 
: desc-raid-escape
	0xFE 0x23 0x0C 0x08 0xF9 0x30 0x1A 0x2C 0xF9 0x27 0x1E 0x1A 0x2B 0x25 0x32 0xF9
	0xFE 0x22 0x14 0x1C 0x1A 0x2E 0x20 0x21 0x2D 0x3F 0xF9 0x13 0x21 0x1A 0x2D 0xF9
	0xFE 0x2E 0x1C 0x30 0x1A 0x2C 0xF9 0x1F 0x1A 0x2B 0xF9 0xFE 0x22 0x24 0x2D 0x28
	0x28 0xF9 0x1C 0x25 0x28 0x2C 0x1E 0xF9 0x1F 0x28 0x2B 0xF9 0xFE 0x29 0x2C 0x1C
	0x28 0x26 0x1F 0x28 0x2B 0x2D 0x3E 0x3E 0x3E 0xFF 
: desc-raid-fail-1
	0xFE 0x1F 0x10 0x01 0x25 0x1A 0x2C 0x2D 0x3F 0xF9 0x02 0x1A 0x2E 0x20 0x21 0x2D
	0x3F 0xF9 0xFE 0x1E 0x18 0x08 0x27 0xF9 0x26 0x32 0xF9 0x21 0x1A 0x2C 0x2D 0x1E
	0xF9 0x2D 0x28 0xF9 0xFE 0x17 0x20 0x1E 0x2C 0x1C 0x1A 0x29 0x1E 0x41 0xF9 0x26
	0x32 0xF9 0x26 0x1A 0x2C 0x24 0xF9 0xFE 0x2B 0x28 0x2C 0x25 0x22 0x29 0x29 0x1E
	0x1D 0x3E 0x3E 0x3E 0xFF
: desc-raid-fail-2
	0xFE 0x27 0x18 0x08 0xF9 0x1D 0x28 0x27 0x42 0x2D 0xF9 0x1F 0x1E 0x1E 0x25 0xF9
	0xFE 0x29 0x20 0x2C 0x28 0xF9 0x20 0x28 0x28 0x1D 0x3E 0x3E 0x3E 0xFF 
: desc-raid-nowrun
	0xFE 0x1C 0x18 0x0D 0x28 0x30 0x41 0xF9 0x08 0xF9 0x27 0x1E 0x1E 0x1D 0xF9 0x2D
	0x28 0xF9 0xF9 0xFE 0x1A 0x20 0x20 0x1E 0x2D 0xF9 0x28 0x2E 0x2D 0xF9 0x28 0x1F
	0xF9 0x21 0x1E 0x2B 0x1E 0x3F 0xFF 

:macro simple-script STRING {
	s-clear
	s-print STRING
	s-pause
	s-end
}
:macro raid-succeed-script {
	s-clear
	s-print desc-raid-succeed
	s-pause
	s-clear
	s-blit img-raid-loot
	s-pause
	simple-script desc-raid-nowrun	
}
: raid-end-succeed-easy
	s-items
	raid-succeed-script
: raid-end-succeed-medium
	s-items
	s-items
	raid-succeed-script
: raid-end-succeed-hard
	s-items
	s-items
	s-items
	s-items
	s-items
	raid-succeed-script
: raid-end-escape
	s-clear
	s-print desc-raid-escape
	s-pause
	simple-script desc-raid-nowrun
: raid-end-fail
	s-clear
	s-print desc-raid-fail-1
	s-pause
	s-clear
	s-print desc-raid-fail-2
	s-pause
	s-inc player-injury
	simple-script desc-raid-nowrun

: raid-table-easy
	pointer raid-end-succeed-easy
	pointer raid-end-succeed-easy
	pointer raid-end-succeed-easy
	pointer raid-end-succeed-easy
	pointer raid-end-succeed-easy
	pointer raid-end-escape
	pointer raid-end-escape
	pointer raid-end-fail
: raid-table-medium
	pointer raid-end-succeed-medium
	pointer raid-end-succeed-medium
	pointer raid-end-succeed-medium
	pointer raid-end-escape
	pointer raid-end-escape
	pointer raid-end-fail
	pointer raid-end-fail
	pointer raid-end-fail
: raid-table-hard
	pointer raid-end-succeed-hard
	pointer raid-end-escape
	pointer raid-end-escape
	pointer raid-end-fail
	pointer raid-end-fail
	pointer raid-end-fail
	pointer raid-end-fail
	pointer raid-end-fail

:macro attempt-raid-script STRING TABLE {
	s-clear
	s-print STRING
	s-pause
	s-random TABLE
}
: script-raid-markets     attempt-raid-script desc-try-raid-markets    raid-table-easy
: script-raid-hospital    attempt-raid-script desc-try-raid-hospital   raid-table-medium
: script-raid-university  attempt-raid-script desc-try-raid-university raid-table-medium
: script-raid-fema        attempt-raid-script desc-try-raid-fema       raid-table-hard
: script-warn-markets     simple-script desc-warn-markets
: script-warn-hospital    simple-script desc-warn-hospital
: script-warn-university  simple-script desc-warn-university
: script-warn-fema        simple-script desc-warn-fema

: raid-warnings
	0x00 0x00                      # 0	
	pointer script-warn-hospital   # 1
	pointer script-warn-fema       # 2
	pointer script-warn-university # 3
	0x00 0x00                      # 4
	pointer script-warn-markets    # 5
	0x00 0x00                      # 6
: raid-scripts
	0x00 0x00                      # 0
	pointer script-raid-hospital   # 1
	pointer script-raid-fema       # 2
	pointer script-raid-university # 3
	0x00 0x00                      # 4
	pointer script-raid-markets    # 5
	0x00 0x00                      # 6

to-code

: handle-raid
	i := long game-zone
	load t2 - t2
	i := long raid-warnings
	script-from-table-t2

	menu-clear
	menu-add 1 str-doraid
	menu-add 0 str-nevermind
	menu
	if t0 == 0 then jump misc-actions

	i := long game-zone
	load t2 - t2
	i := long raid-scripts
	script-from-table-t2
	jump travel

###########################################
#
#  Gambling
#
###########################################

to-data

: BIG_MIN_BET  0 0  0 0 0  0 1 0
: BIG_MED_BET  0 0  0 0 0  0 5 0
: BIG_MAX_BET  0 0  0 0 0  2 5 0

: str-bet10  0x01 0x1E 0x2D 0xF9 0x35 0x34 0xFF
: str-bet50  0x01 0x1E 0x2D 0xF9 0x39 0x34 0xFF
: str-bet250 0x01 0x1E 0x2D 0xF9 0x36 0x39 0x34 0xFF
: str-leave  0x0B 0x1E 0x1A 0x2F 0x1E 0xFF
: str-hit    0x07 0x22 0x2D 0xFF
: str-stand  0x12 0x2D 0x1A 0x27 0x1D 0xFF

: img-blackjack
	0x00 0x00 0x08 0x00 0x1C 0x00 0x1C 0x00 0x3E 0x00 0x7F 0x00 0x7F 0x00 0x3E 0x00
	0x08 0x00 0x1C 0x00 0x3E 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x38 0x00 0xFE 0x07 0xFF 0x0F 0xE7 0x03 0x83 0x01 0x83 0x01 0x87 0x01 0xFE
	0x01 0xFF 0x01 0x87 0x01 0x83 0x03 0x83 0x07 0xC7 0x03 0xFF 0x00 0xFF 0x00 0x7C
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x08 0x00 0x14 0x00 0x22 0x00
	0x22 0x00 0x41 0x00 0x41 0x00 0x22 0x00 0x22 0x00 0x14 0x00 0x08 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x0E 0x00 0x18 0x00 0xB3 0xF0 0xB4 0x78 0x31 0xF9 0x33 0xD9
	0x37 0x9B 0xB7 0x1B 0xB7 0x3B 0xB7 0xB3 0xB3 0xF1 0xB0 0xF8 0x3E 0x00 0x78 0x00
	0xE0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x18 0x03 0x0E 0x03 0x06 0x07 0xE6 0x16 0xD3 0xB0 0x83 0xF3
	0x83 0xE3 0x8B 0x61 0x9B 0x71 0xDB 0x31 0xF3 0x3B 0xE7 0x3B 0x0F 0x3B 0x0F 0x03
	0x00 0x06 0x00 0x1C 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x1F 0x80 0x23 0xC7 0x8F 0xCE 0x9E 0xCC
	0xBC 0xDC 0xB8 0xDC 0xB9 0xDC 0xBD 0x9E 0x9F 0x8F 0x87 0xC7 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x0D 0x00 0x12 0x00 0x22 0x00 0x20 0x00 0x10 0x00 0x08 0x00 0x05
	0x00 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x06 0x00 0x1E
	0x00 0x3C 0x00 0x7C 0xC0 0x3C 0x70 0x3C 0x30 0x38 0x30 0x98 0x9D 0x98 0x1F 0x98
	0x1F 0x18 0x5B 0x10 0xDB 0x80 0xD9 0x98 0x99 0xD8 0x39 0xC0 0x79 0xC0 0x78 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x06 0x00 0x0F
	0x00 0x0F 0x00 0x36 0x00 0x7F 0x00 0x7F 0x00 0x36 0x00 0x0F 0x00 0x1F 0x00 0x00
	0x00 0x80 0x81 0xC0 0x41 0xC0 0x23 0xE0 0x27 0xF0 0x47 0xF0 0x83 0xE0 0x00 0x80
	0x01 0xC0 0x03 0xE0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x03
	0x00 0x0F 0x00 0x7F 0x00 0xFE 0x00 0x38 0x00 0x18 0x00 0x18 0x00 0x1F 0x00 0x1F
	0x00 0x18 0x00 0x18 0x00 0x38 0x00 0x7C 0x00 0x3F 0x00 0x0F 0x00 0x07 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x01 0x40 0x02 0x20 0x02 0x20
	0x04 0x10 0xC4 0x10 0xE2 0x20 0xE2 0x20 0xC1 0x40 0x00 0x80 0x80 0x00 0x00 0x00

: desc-gamble-nocash
	0xFE 0x28 0x14 0x08 0x42 0x26 0xF9 0x1B 0x2B 0x28 0x24 0x1E 0x3E 0xF9 0xFE 0x1E
	0x1C 0x0D 0x28 0xF9 0x1C 0x1A 0x2C 0x22 0x27 0x28 0x2C 0xF9 0x1F 0x28 0x2B 0xF9
	0xFE 0x25 0x24 0x26 0x1E 0xF9 0x2D 0x28 0x27 0x22 0x20 0x21 0x2D 0x3E 0xFF
: desc-gamble-intro
	0xFE 0x1F 0x0C 0x08 0x27 0xF9 0x1A 0xF9 0x2B 0x2E 0x27 0x1D 0x28 0x30 0x27 0xF9
	0xF9 0xFE 0x2B 0x14 0x1C 0x1A 0x2C 0x22 0x27 0x28 0x41 0xF9 0x1A 0xF9 0xFE 0x27
	0x1C 0x02 0x1A 0x2B 0x1D 0x2C 0x21 0x1A 0x2B 0x29 0xF9 0xFE 0x22 0x24 0x22 0x2C
	0xF9 0x2B 0x2E 0x27 0x27 0x22 0x27 0x20 0xF9 0x1A 0xF9 0xF9 0xFE 0x25 0x2C 0x20
	0x1A 0x26 0x1E 0xF9 0x28 0x1F 0xF9 0x36 0x35 0x3E 0xFF 
: desc-gamble-yourbet
	0xFE 0x21 0x10 0x44 0x13 0x21 0x1E 0xF9 0x20 0x1A 0x26 0x1E 0xF9 0x22 0x2C 0xF9
	0xFE 0x28 0x18 0x01 0x25 0x1A 0x1C 0x24 0x23 0x1A 0x1C 0x24 0x3E 0xF9 0xFE 0x19
	0x20 0x16 0x21 0x1A 0x2D 0x42 0x2C 0xF9 0x32 0x28 0x2E 0x2B 0xF9 0x1B 0x1E 0x2D
	0x41 0xF9 0xFE 0x34 0x28 0x29 0x1A 0x25 0x40 0x44 0xFF
: gamble-status-headers
	0xFE 0x1E 0x14 0x0F 0x25 0x1A 0x32 0x1E 0x2B 0xF9 0xFE 0x1E 0x24 0x03 0x1E 0x1A
	0x25 0x1E 0x2B 0xFF
: desc-gamble-player-wins
	0xFE 0x2C 0x1C 0x18 0x28 0x2E 0xF9 0x16 0x22 0x27 0x3F 0xFF 
: desc-gamble-player-blackjack
	0xFE 0x18 0x18 0x18 0x28 0x2E 0xF9 0x30 0x22 0x27 0xF9 0x38 0xF9 0x2D 0x22 0x26
	0x1E 0x2C 0xF9 0xF9 0xFE 0x2A 0x20 0x32 0x28 0x2E 0x2B 0xF9 0x1B 0x1E 0x2D 0x3F
	0xFF
: desc-gamble-player-busts
	0xFE 0x35 0x18 0x01 0x2E 0x2C 0x2D 0x3F 0xF9 0xFE 0x2A 0x20 0x18 0x28 0x2E 0xF9
	0x25 0x28 0x2C 0x1E 0x3F 0xFF
: desc-gamble-dealer-wins
	0xFE 0x23 0x18 0x03 0x1E 0x1A 0x25 0x1E 0x2B 0xF9 0x30 0x22 0x27 0x2C 0x3E 0xF9
	0xFE 0x32 0x20 0x03 0x1A 0x26 0x27 0x3E 0xFF
: desc-gamble-dealer-busts
	0xFE 0x21 0x18 0x03 0x1E 0x1A 0x25 0x1E 0x2B 0xF9 0x1B 0x2E 0x2C 0x2D 0x2C 0x3E
	0xF9 0xFE 0x2C 0x20 0x18 0x28 0x2E 0xF9 0x30 0x22 0x27 0x3F 0xFF

: script-gamble-blackjack
	s-clear
	s-blit img-blackjack
	s-pause
	s-clear
	s-print desc-gamble-player-blackjack
	s-pause
	s-end
: script-gamble-nocash
	s-clear
	s-print desc-gamble-nocash
	s-pause
	s-end
: script-gamble-intro
	s-clear
	s-print desc-gamble-intro
	s-pause
	s-clear
	s-print desc-gamble-yourbet
	s-pause
	s-end

to-code

: deal-card
	v1 := 9
	random-upto-v1
	v0 += 2
;
: gamble-status
	clear
	print gamble-status-headers
	decode2 vA
	cursor-x := 100
	cursor-y := 20
	unpack16 BIG_DECODE2
	number-nokia
	cursor-y := 36
	decode2 vB
	number-nokia
;

: gamble-player-wins
	print desc-gamble-player-wins
	dialog-pause
: gamble-win-x2
	add BIG_DECODE PLAYER_CASH
	n-add # x2
	jump gamble-main
: gamble-player-blackjack
	script script-gamble-blackjack
	add BIG_DECODE PLAYER_CASH # x4
	jump gamble-win-x2
: gamble-player-busts
	print desc-gamble-player-busts
	dialog-pause
	jump gamble-main
: gamble-dealer-wins
	print desc-gamble-dealer-wins
	dialog-pause
	jump gamble-main
: gamble-dealer-busts
	print desc-gamble-dealer-busts
	dialog-pause
	jump gamble-win-x2

: handle-gamble
	more BIG_MIN_BET PLAYER_CASH # ve := (b >= a)
	if ve == 0 begin
		script script-gamble-nocash
		jump misc-actions
	end
	script script-gamble-intro
: gamble-main
	menu-clear
	more BIG_MIN_BET PLAYER_CASH
	if ve != 0 begin vf := -1 menu-add  10 str-bet10 end
	more BIG_MED_BET PLAYER_CASH
	if ve != 0 begin vf := -1 menu-add  50 str-bet50 end
	more BIG_MAX_BET PLAYER_CASH
	if ve != 0 begin vf := -1 menu-add 250 str-bet250 end
	vf := -1
	menu-add 0 str-leave
	menu
	if t0 == 0 then jump misc-actions
	decode t0
	sub BIG_DECODE PLAYER_CASH

	vA := 0 # player
	vB := 0 # dealer
	loop
		deal-card vA += v0
		if vB < 17 begin
			deal-card
			vB += v0
		end
		gamble-status
		dialog-pause
		clear
		if vB == 21 then jump gamble-dealer-wins
		if vA == 21 then jump gamble-player-blackjack
		if vA > 21 then jump gamble-player-busts
		if vB > 21 then jump gamble-dealer-busts
		menu-clear
		menu-add 1 str-hit
		menu-add 0 str-stand
		menu
		while t0 != 0
	again
	# resolve remaining dealer moves...
	loop
		while vB < 17
		deal-card
		vB += v0
		gamble-status
		wait wait wait
	again
	# resolve endgame from a stand...
	clear
	if vB == 21 then jump gamble-dealer-wins
	if vB > 21 then jump gamble-dealer-busts
	if vB > vA then jump gamble-dealer-wins
	jump gamble-player-wins

###########################################
#
#  Inventory
#
###########################################

to-data

: str-nothing 0x0D 0x28 0x2D 0x21 0x22 0x27 0x20 0xFF

to-code

: handle-inventory
	menu-clear
	t0 := 0
	loop
		i := long item-owned
		i += t0
		load t1 - t1
		if t1 != 0 begin
			i := long item-name-table
			i += t0
			i += t0
			load v1
			ve := t0
			vf := t1
			menu-add-body
		end
		t0 += 1
		if t0 != ITEM_TYPES then
	again
	if menu-count == 0 begin
		menu-add 0 str-nothing
	end
	menu
	jump misc-actions

###########################################
#
#  Random Events
#
###########################################

to-data

: img-newsflash
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xC0 0xFF 0xBF 0xFF 0xB8 0xFF 0x7C 0xFF 0x7F 0xFE 0xFC 0xFE 0xFC
	0xFD 0xF8 0xFD 0xF8 0xFB 0xF0 0xFB 0xF0 0xF7 0xE0 0xF7 0xE0 0xEF 0xC0 0xEF 0xC0
	0xDF 0x81 0xDF 0x81 0xDF 0x02 0xEF 0x02 0xF6 0x05 0xFB 0xFD 0xFC 0x03 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0x00 0x00 0xFF 0xFF 0x00 0x00 0xFF 0xFF 0x00 0x00 0xFF 0xFF
	0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0x7C 0x01 0xBB 0xFE 0x5B 0x01 0x27 0x80 0xF7 0xFF 0x0F 0xC0 0x07 0x80
	0x03 0x81 0x01 0x01 0x01 0x03 0x00 0x03 0x00 0x07 0x00 0x07 0x00 0x0F 0x00 0x0F
	0x00 0x1E 0x00 0x1E 0x80 0x3C 0x40 0x3C 0xA0 0x58 0xDF 0xCF 0xE0 0x30 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0x40 0xF9 0xC0 0xF9 0x4F 0xF9 0xC1 0xF9 0x41 0xF9 0xCF 0xF8
	0x4F 0xF8 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x7F 0xFF 0xBF 0xFF 0x5F 0xFF 0x80 0x06 0xFF 0xF9
	0x00 0x07 0x80 0x03 0xFF 0xFF 0xC0 0x01 0x80 0x03 0x80 0x07 0x01 0xFF 0x00 0x07
	0x00 0x0F 0x00 0x1F 0x03 0xFE 0x00 0x1E 0x00 0x2C 0xFF 0xE7 0x00 0x18 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFE 0x0F 0xFC 0x07 0xFC 0xE7 0xFC 0x07 0xFC 0x07 0x3C 0xE7
	0x3C 0xE7 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x10 0x83 0xEF 0x7C
	0x9C 0xE3 0xCE 0x71 0xFF 0xFF 0xE7 0x38 0xC6 0x31 0xC4 0x21 0x80 0x03 0x80 0x03
	0x00 0x07 0x00 0x07 0x02 0x0F 0x06 0x0F 0x0A 0x16 0xF3 0xF3 0x0C 0x0C 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0x81 0xE7 0x81 0xE7 0x9F 0xE0 0x81 0xE0 0xF9 0xE7 0x81 0xE7
	0x81 0xE7 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00 0x01 0xFF 0xFE
	0xC0 0x01 0xE0 0x00 0xFF 0xFF 0xF0 0x00 0xE0 0x00 0xE0 0x01 0xC0 0x7F 0xC0 0x01
	0x80 0x02 0x80 0x02 0xFC 0x05 0x00 0x05 0x00 0x0B 0xFF 0xFB 0x00 0x07 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0x20 0x00 0x3F 0xFF 0x20 0x00 0x3F 0xFF 0x20 0x00 0x3F 0xFF
	0x20 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0x7F 0xFF 0xBF 0xFF 0xDF 0xFF 0x5F 0xFF 0xBF 0xFF 0xBF 0xFF 0x7F 0xFF 0x7F 0xFF
	0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
	0xFF 0xFF 0xFF 0xFF 0x0F 0xFF 0xFF 0xFF 0x0F 0xFF 0xFF 0xFF 0x0F 0xFF 0xFF 0xFF
	0x0F 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

: desc-news-0 # unknown origin
	0xFE 0x25 0x0C 0x00 0xF9 0x29 0x25 0x1A 0x20 0x2E 0x1E 0xF9 0x28 0x1F 0xF9 0xFE
	0x1B 0x14 0x2E 0x27 0x24 0x27 0x28 0x30 0x27 0xF9 0x28 0x2B 0x22 0x20 0x22 0x27
	0xF9 0xFE 0x20 0x1C 0x20 0x2B 0x22 0x29 0x2C 0xF9 0x2D 0x21 0x1E 0xF9 0x1C 0x22
	0x2D 0x32 0xF9 0xFE 0x29 0x24 0x30 0x22 0x2D 0x21 0xF9 0x1F 0x1E 0x1A 0x2B 0x3F
	0xF9 0xFE 0x24 0x2C 0x0C 0x28 0x2B 0x1E 0xF9 0x1A 0x2D 0xF9 0x35 0x35 0x3E 0x3E
	0x3E 0xFF 
: desc-news-1 # avian source?
	0xFE 0x22 0x0C 0x11 0x1E 0x2C 0x1E 0x1A 0x2B 0x1C 0x21 0x1E 0x2B 0x2C 0xF9 0xFE
	0x28 0x14 0x1B 0x1A 0x1F 0x1F 0x25 0x1E 0x1D 0xF9 0x1B 0x32 0xF9 0xFE 0x1C 0x1C
	0x29 0x25 0x1A 0x20 0x2E 0x1E 0xF9 0x2C 0x28 0x2E 0x2B 0x1C 0x1E 0x43 0xF9 0xFE
	0x1D 0x24 0x12 0x28 0x26 0x1E 0xF9 0x2D 0x21 0x1E 0x28 0x2B 0x22 0x33 0x1E 0xF9
	0xFE 0x1F 0x2C 0x00 0x2F 0x22 0x1A 0x27 0xF9 0x28 0x2B 0x22 0x20 0x22 0x27 0x3E
	0x3E 0x3E 0xFF 
: desc-news-2 # hundreds dead
	0xFE 0x21 0x0C 0x02 0x28 0x27 0x1D 0x22 0x2D 0x22 0x28 0x27 0x2C 0xF9 0x22 0x27
	0xF9 0xFE 0x1D 0x14 0x1C 0x22 0x2D 0x32 0xF9 0x30 0x28 0x2B 0x2C 0x1E 0x27 0xF9
	0x1A 0x2C 0xF9 0xFE 0x1E 0x1C 0x0F 0x25 0x1A 0x20 0x2E 0x1E 0xF9 0x1D 0x1E 0x1A
	0x2D 0x21 0x2C 0xF9 0xFE 0x1E 0x24 0x27 0x2E 0x26 0x1B 0x1E 0x2B 0xF9 0x22 0x27
	0xF9 0x2D 0x21 0x1E 0xF9 0xFE 0x28 0x2C 0x21 0x2E 0x27 0x1D 0x2B 0x1E 0x1D 0x2C
	0x3F 0xFF 
: desc-news-3 # thousands dead
	0xFE 0x19 0x0C 0x13 0x21 0x28 0x2E 0x2C 0x1A 0x27 0x1D 0x2C 0xF9 0x1D 0x1E 0x1A
	0x1D 0xF9 0xFE 0x1C 0x14 0x1A 0x2C 0xF9 0x2B 0x1E 0x2C 0x1E 0x1A 0x2B 0x1C 0x21
	0x1E 0x2B 0x2C 0xF9 0xFE 0x1A 0x1C 0x2C 0x2D 0x22 0x25 0x25 0xF9 0x2B 0x1A 0x1C
	0x1E 0xF9 0x2D 0x28 0xF9 0x1F 0x22 0x27 0x1D 0xF9 0xFE 0x28 0x24 0x1A 0xF9 0x1C
	0x2E 0x2B 0x1E 0xF9 0x1F 0x28 0x2B 0xF9 0xFE 0x17 0x2C 0x26 0x32 0x2C 0x2D 0x1E
	0x2B 0x32 0xF9 0x1D 0x22 0x2C 0x1E 0x1A 0x2C 0x1E 0x3F 0xFF 
: desc-news-4 # all city services shut down
	0xFE 0x18 0x0C 0x00 0x2E 0x2D 0x21 0x28 0x2B 0x22 0x2D 0x22 0x1E 0x2C 0xF9 0x30
	0x1A 0x2B 0x27 0xF9 0xFE 0x1C 0x14 0x28 0x1F 0xF9 0x2C 0x21 0x2E 0x2D 0x1D 0x28
	0x30 0x27 0xF9 0x28 0x1F 0xF9 0xFE 0x1A 0x1C 0x1A 0x25 0x25 0xF9 0x1C 0x22 0x2D
	0x32 0xF9 0x2C 0x1E 0x2B 0x2F 0x22 0x1C 0x1E 0x2C 0xF9 0xFE 0x27 0x24 0x22 0x27
	0xF9 0x30 0x1A 0x24 0x1E 0xF9 0x28 0x1F 0xF9 0xFE 0x19 0x2C 0x29 0x25 0x1A 0x20
	0x2E 0x1E 0xF9 0x1D 0x22 0x2C 0x1A 0x2C 0x2D 0x1E 0x2B 0x3F 0xFF 
: desc-news-5 # martial law
	0xFE 0x20 0x0C 0x02 0x22 0x2D 0x32 0xF9 0x22 0x27 0xF9 0x1C 0x21 0x1A 0x28 0x2C
	0x3F 0xF9 0xFE 0x1F 0x14 0x26 0x22 0x25 0x25 0x22 0x28 0x27 0x2C 0xF9 0x1D 0x1E
	0x1A 0x1D 0x41 0xF9 0xFE 0x21 0x1C 0x05 0x1E 0x1D 0xF9 0x1D 0x1E 0x1C 0x25 0x1A
	0x2B 0x1E 0x2C 0xF9 0xFE 0x23 0x24 0x26 0x1A 0x2B 0x2D 0x22 0x1A 0x25 0xF9 0x25
	0x1A 0x30 0x3F 0xF9 0xFE 0x24 0x2C 0x0C 0x28 0x2B 0x1E 0xF9 0x1A 0x2D 0xF9 0x35
	0x35 0x3E 0x3E 0x3E 0xFF 

:macro news-script STRING {
	s-clear
	s-blit img-newsflash
	s-pause
	s-clear
	s-print STRING
	s-pause
	s-inc news-index
	s-end
}
: script-news-0 news-script desc-news-0
: script-news-1 news-script desc-news-1
: script-news-2 news-script desc-news-2
: script-news-3 news-script desc-news-3
: script-news-4 news-script desc-news-4
: script-news-5 news-script desc-news-5
: news-script-table
	pointer script-news-0
	pointer script-news-1
	pointer script-news-2
	pointer script-news-3
	pointer script-news-4
	pointer script-news-5

: desc-unlock-0 # antivirals
	0xFE 0x1C 0x10 0x00 0x27 0x2D 0x22 0x2F 0x22 0x2B 0x1A 0x25 0xF9 0x1D 0x2B 0x2E
	0x20 0x2C 0xF9 0xFE 0x21 0x18 0x21 0x1A 0x2F 0x1E 0xF9 0x2C 0x2D 0x1A 0x2B 0x2D
	0x1E 0x1D 0xF9 0xFE 0x1F 0x20 0x2C 0x21 0x28 0x30 0x22 0x27 0x20 0xF9 0x2E 0x29
	0xF9 0x22 0x27 0xF9 0xFE 0x28 0x28 0x26 0x1A 0x2B 0x24 0x1E 0x2D 0x2C 0x3E 0x3E
	0x3E 0xFF
: desc-unlock-1 # vaccines
	0xFE 0x18 0x10 0x0F 0x25 0x1A 0x20 0x2E 0x1E 0xF9 0x2F 0x1A 0x1C 0x1C 0x22 0x27
	0x1E 0x2C 0xF9 0xFE 0x20 0x18 0x21 0x1A 0x2F 0x1E 0xF9 0x2C 0x2D 0x1A 0x2B 0x2D
	0x1E 0x1D 0xF9 0xFE 0x1E 0x20 0x2C 0x21 0x28 0x30 0x22 0x27 0x20 0xF9 0x2E 0x29
	0xF9 0x22 0x27 0xF9 0xFE 0x28 0x28 0x26 0x1A 0x2B 0x24 0x1E 0x2D 0x2C 0x3E 0x3E
	0x3E 0xFF 
: desc-unlock-2 # painkillers
	0xFE 0x1D 0x10 0x0F 0x1A 0x22 0x27 0x24 0x22 0x25 0x25 0x1E 0x2B 0x2C 0xF9 0x1A
	0x2B 0x1E 0xF9 0xFE 0x19 0x18 0x20 0x1E 0x2D 0x2D 0x22 0x27 0x20 0xF9 0x29 0x28
	0x29 0x2E 0x25 0x1A 0x2B 0x41 0xF9 0xFE 0x20 0x20 0x1A 0x2C 0xF9 0x21 0x28 0x29
	0x1E 0xF9 0x1F 0x28 0x2B 0xF9 0x1A 0xF9 0xFE 0x22 0x28 0x1C 0x2E 0x2B 0x1E 0xF9
	0x1F 0x1A 0x1D 0x1E 0x2C 0x3E 0x3E 0x3E 0xFF
:macro unlock-script STRING OFFSET {
	s-clear
	s-print STRING
	s-pause
	s-inc unlock-index
	:calc t-unlock { item-unlocked + OFFSET }
	s-inc t-unlock
	s-end
}
: script-unlock-0 unlock-script desc-unlock-0 4
: script-unlock-1 unlock-script desc-unlock-1 5
: script-unlock-2 unlock-script desc-unlock-2 6
: unlock-script-table
	pointer script-unlock-0
	pointer script-unlock-1
	pointer script-unlock-2

: desc-reward
	0xFE 0x1D 0x0C 0x08 0xF9 0x2C 0x2D 0x2E 0x26 0x1B 0x25 0x1E 0xF9 0x2E 0x29 0x28
	0x27 0xF9 0xFE 0x1C 0x14 0x1A 0xF9 0x21 0x22 0x1D 0x1D 0x1E 0x27 0xF9 0x1C 0x1A
	0x1C 0x21 0x1E 0xF9 0xFE 0x25 0x1C 0x28 0x1F 0xF9 0x2C 0x2E 0x29 0x29 0x25 0x22
	0x1E 0x2C 0x3E 0xF9 0xFE 0x19 0x24 0x0C 0x22 0x20 0x21 0x2D 0xF9 0x1B 0x1E 0xF9
	0x1A 0x1B 0x25 0x1E 0xF9 0x2D 0x28 0xF9 0xFE 0x29 0x2C 0x2C 0x1E 0x25 0x25 0xF9
	0x2D 0x21 0x22 0x2C 0x3E 0x3E 0x3E 0xFF
: script-reward
	s-clear
	s-print desc-reward
	s-items
	s-pause
	s-end

: desc-dealer-nogun
	0xFE 0x1F 0x0C 0x00 0xF9 0x1C 0x28 0x27 0x2D 0x1A 0x1C 0x2D 0xF9 0x2D 0x28 0x25
	0x1D 0xF9 0xFE 0x24 0x14 0x26 0x1E 0xF9 0x1A 0x27 0xF9 0x1A 0x2B 0x26 0x2C 0xF9
	0xFE 0x19 0x1C 0x1D 0x1E 0x1A 0x25 0x1E 0x2B 0xF9 0x28 0x29 0x1E 0x2B 0x1A 0x2D
	0x1E 0x2C 0xF9 0xFE 0x27 0x24 0x27 0x1E 0x1A 0x2B 0xF9 0x21 0x1E 0x2B 0x1E 0x3E
	0xF9 0xFE 0x27 0x2C 0x08 0xF9 0x30 0x28 0x27 0x1D 0x1E 0x2B 0x3E 0x3E 0x3E 0xFF
: desc-dealer-gun
	0xFE 0x1B 0x10 0x08 0xF9 0x21 0x1A 0x2F 0x1E 0xF9 0x1A 0xF9 0x1C 0x21 0x1A 0x27
	0x1C 0x1E 0xF9 0xFE 0x1A 0x18 0x2D 0x28 0xF9 0x26 0x1E 0x1E 0x2D 0xF9 0x2E 0x29
	0xF9 0x30 0x22 0x2D 0x21 0xF9 0xFE 0x17 0x20 0x2D 0x21 0x1A 0x2D 0xF9 0x1A 0x2B
	0x26 0x2C 0xF9 0x1D 0x1E 0x1A 0x25 0x1E 0x2B 0xF9 0xFE 0x2F 0x28 0x1A 0x20 0x1A
	0x22 0x27 0x3E 0x3E 0x3E 0xFF
: script-find-dealer-nogun
	s-clear
	s-print desc-dealer-nogun
	s-pause
	s-end
: script-find-dealer-gun
	s-clear
	s-print desc-dealer-gun
	s-pause
	s-end
:calc bullets-addr   { item-owned    + 7 }
:calc bullets-unlock { item-unlocked + 7 }
: script-buy-gun
	s-inc has-gun
: script-buy-bullets
	s-inc bullets-addr
	s-inc bullets-addr
	s-inc bullets-addr
	s-inc bullets-addr
	s-inc bullets-addr
	s-inc bullets-addr
	s-end

: BIG_GUN_PRICE     0 0  0 0 0  2 5 0
: BIG_BULLETS_PRICE 0 0  0 0 0  0 5 0

: str-buy-gun        0x01 0x2E 0x32 0xF9 0x20 0x2E 0x27 0xFF
: str-buy-bullets    0x01 0x2E 0x32 0xF9 0x1B 0x2E 0x25 0x25 0x1E 0x2D 0x2C 0xFF
: str-not-interested 0x0D 0x28 0x2D 0xF9 0x22 0x27 0x2D 0x1E 0x2B 0x1E 0x2C 0x2D 0x1E 0x1D 0xFF

: desc-begin-mugging
	0xFE 0x1D 0x0C 0x03 0x1E 0x2C 0x29 0x1E 0x2B 0x1A 0x2D 0x1E 0xF9 0x2C 0x22 0x1C
	0x24 0xF9 0xFE 0x1E 0x14 0x1A 0x2B 0x1E 0xF9 0x1A 0x2D 0x2D 0x1A 0x1C 0x24 0x22
	0x27 0x20 0x41 0xF9 0xFE 0x1C 0x1C 0x2D 0x2B 0x32 0x22 0x27 0x20 0xF9 0x2D 0x28
	0xF9 0x26 0x1A 0x24 0x1E 0xF9 0xFE 0x25 0x24 0x28 0x1F 0x1F 0xF9 0x30 0x22 0x2D
	0x21 0xF9 0x26 0x32 0xF9 0xFE 0x20 0x2C 0x26 0x1E 0x2B 0x1C 0x21 0x1A 0x27 0x1D
	0x22 0x2C 0x1E 0x3F 0xFF
: script-begin-mugging
	s-clear
	s-print desc-begin-mugging
	s-pause
	s-end

: str-use-gun   0x14 0x2C 0x1E 0xF9 0x26 0x32 0xF9 0x20 0x2E 0x27 0xFF 
: str-flee      0x13 0x2B 0x32 0xF9 0x2D 0x28 0xF9 0x1F 0x25 0x1E 0x1E 0xFF 
: str-surrender 0x12 0x2E 0x2B 0x2B 0x1E 0x27 0x1D 0x1E 0x2B 0xFF

: desc-fire-gun
	0xFE 0x25 0x18 0x08 0xF9 0x28 0x29 0x1E 0x27 0xF9 0x1F 0x22 0x2B 0x1E 0x43 0xF9
	0xFE 0x33 0x20 0x01 0x0B 0x00 0x0C 0x3F 0xFF
: desc-gun-success
	0xFE 0x23 0x0C 0x01 0x25 0x28 0x28 0x1D 0xF9 0x1F 0x25 0x28 0x30 0x2C 0x3F 0xF9
	0xFE 0x1E 0x14 0x0C 0x32 0xF9 0x1A 0x2D 0x2D 0x1A 0x1C 0x24 0x1E 0x2B 0xF9 0x22
	0x2C 0xF9 0xFE 0x20 0x1C 0x1D 0x28 0x30 0x27 0x1E 0x1D 0xF9 0x22 0x27 0xF9 0x1A
	0x27 0xF9 0xFE 0x2E 0x24 0x22 0x27 0x2C 0x2D 0x1A 0x27 0x2D 0x3E 0xF9 0xFE 0x1C
	0x2C 0x06 0x28 0x28 0x1D 0xF9 0x2B 0x22 0x1D 0x1D 0x1A 0x27 0x1C 0x1E 0x3F 0xFF
: desc-gun-failure
	0xFE 0x19 0x0C 0x0C 0x22 0x2C 0x2C 0x1E 0x1D 0x3F 0xF9 0x03 0x1A 0x26 0x27 0xF9
	0x22 0x2D 0x3F 0xF9 0xFE 0x24 0x14 0x08 0xF9 0x26 0x1A 0x27 0x1A 0x20 0x1E 0xF9
	0x2D 0x28 0xF9 0xFE 0x1C 0x1C 0x1E 0x2C 0x1C 0x1A 0x29 0x1E 0x41 0xF9 0x1B 0x2E
	0x2D 0xF9 0x08 0x42 0x26 0xF9 0xFE 0x1F 0x24 0x22 0x27 0x23 0x2E 0x2B 0x1E 0x1D
	0xF9 0x22 0x27 0xF9 0x2D 0x21 0x1E 0xF9 0xFE 0x2C 0x2C 0x2C 0x1C 0x2E 0x1F 0x1F
	0x25 0x1E 0x3E 0x3E 0x3E 0xFF
: desc-try-flee
	0xFE 0x1B 0x14 0x08 0xF9 0x20 0x2E 0x27 0xF9 0x22 0x2D 0x41 0xF9 0x1A 0x27 0x1D
	0xF9 0x2D 0x2B 0x32 0xF9 0xFE 0x20 0x1C 0x2D 0x28 0xF9 0x1E 0x2C 0x1C 0x1A 0x29
	0x1E 0xF9 0x26 0x32 0xF9 0xFE 0x24 0x24 0x1A 0x2C 0x2C 0x1A 0x22 0x25 0x1A 0x27
	0x2D 0x2C 0x3E 0x3E 0x3E 0xFF
: desc-flee-success
	0xFE 0x21 0x10 0x0C 0x32 0xF9 0x30 0x28 0x2E 0x25 0x1D 0x43 0x1B 0x1E 0xF9 0xFE
	0x1F 0x18 0x1A 0x2D 0x2D 0x1A 0x1C 0x24 0x1E 0x2B 0x2C 0xF9 0x1A 0x2B 0x1E 0xF9
	0xFE 0x1B 0x20 0x25 0x1E 0x1F 0x2D 0xF9 0x22 0x27 0xF9 0x2D 0x21 0x1E 0xF9 0x1D
	0x2E 0x2C 0x2D 0x3E 0xF9 0xFE 0x29 0x28 0x13 0x28 0x28 0xF9 0x1E 0x1A 0x2C 0x32
	0x3E 0xFF
: desc-flee-failure
	0xFE 0x17 0x0C 0x08 0x42 0x26 0xF9 0x27 0x28 0x2D 0xF9 0x2A 0x2E 0x22 0x2D 0x1E
	0xF9 0x1F 0x1A 0x2C 0x2D 0xF9 0xFE 0x17 0x14 0x1E 0x27 0x28 0x2E 0x20 0x21 0x3E
	0xF9 0x08 0xF9 0x20 0x1E 0x2D 0xF9 0x28 0x2E 0x2D 0xF9 0xFE 0x19 0x1C 0x28 0x1F
	0xF9 0x2D 0x21 0x1E 0x2B 0x1E 0x41 0xF9 0x1B 0x2E 0x2D 0xF9 0x08 0x42 0x26 0xF9
	0xFE 0x1F 0x24 0x22 0x27 0x23 0x2E 0x2B 0x1E 0x1D 0xF9 0x22 0x27 0xF9 0x2D 0x21
	0x1E 0xF9 0xFE 0x2C 0x2C 0x2C 0x1C 0x2E 0x1F 0x1F 0x25 0x1E 0x3E 0x3E 0x3E 0xFF
: desc-surrendered
	0xFE 0x22 0x08 0x08 0xF9 0x2C 0x2E 0x2B 0x2B 0x1E 0x27 0x1D 0x1E 0x2B 0x41 0xF9
	0xFE 0x1D 0x10 0x1A 0x27 0x1D 0xF9 0x2D 0x21 0x1E 0x32 0xF9 0x2D 0x1A 0x24 0x1E
	0xF9 0xFE 0x1D 0x18 0x00 0x0B 0x0B 0xF9 0x26 0x32 0xF9 0x1C 0x1A 0x2B 0x20 0x28
	0x3E 0xF9 0xFE 0x25 0x20 0x08 0x27 0x1F 0x2E 0x2B 0x22 0x1A 0x2D 0x22 0x27 0x20
	0x3F 0xF9 0xFE 0x2B 0x28 0x00 0x2D 0xF9 0x25 0x1E 0x1A 0x2C 0x2D 0xF9 0x08 0xF9
	0xFE 0x28 0x30 0x1E 0x2C 0x1C 0x1A 0x29 0x1E 0x1D 0x3E 0x3E 0x3E 0xFF 

: script-use-gun-success
	s-clear
	s-print desc-gun-success
	s-pause
	s-end
: script-use-gun-failure
	s-clear
	s-print desc-gun-failure
	s-pause
	s-inc player-injury
	s-end
: script-use-gun-table # 3/4 odds
	pointer script-use-gun-success
	pointer script-use-gun-success
	pointer script-use-gun-success
	pointer script-use-gun-success
	pointer script-use-gun-success
	pointer script-use-gun-success
	pointer script-use-gun-failure
	pointer script-use-gun-failure
: script-use-gun
	s-dec bullets-addr
	s-clear
	s-print desc-fire-gun
	s-pause
	s-random script-use-gun-table

: script-flee-success
	s-clear
	s-print desc-flee-success
	s-pause
	s-end
: script-flee-failure
	s-clear
	s-inc player-injury
	s-print desc-flee-failure
	s-pause
	s-end
: script-flee-table # 1/4 odds
	pointer script-flee-success
	pointer script-flee-success
	pointer script-flee-failure
	pointer script-flee-failure
	pointer script-flee-failure
	pointer script-flee-failure
	pointer script-flee-failure
	pointer script-flee-failure
: script-flee
	s-clear
	s-print desc-try-flee
	s-pause
	s-random script-flee-table

: script-surrender
	s-clear
	s-print desc-surrendered
	s-pause
	s-end

to-code

: handle-newsflash
	i := long news-index
	load t2 - t2
	i := long news-script-table
	jump script-from-table-t2

: handle-unlock
	i := long unlock-index
	load t2 - t2
	i := long unlock-script-table
	jump script-from-table-t2

: handle-reward
	script script-reward
	return

: handle-arms-dealer
	i := long has-gun
	load v0 - v0
	if v0 == 0 begin
		# doesn't own a gun
		more BIG_GUN_PRICE PLAYER_CASH
		if ve == 0 then return
		script script-find-dealer-nogun
		menu-clear
		vd := 1
		vf := 250
		menu-add 1 str-buy-gun
		vf := -1
		menu-add 0 str-not-interested
		menu
		if t0 == 0 then return
		sub BIG_GUN_PRICE PLAYER_CASH
		script script-buy-gun
	else
		# already owns a gun
		more BIG_GUN_PRICE PLAYER_CASH
		if ve == 0 then return
		script script-find-dealer-gun
		menu-clear
		vd := 1
		vf := 50
		menu-add 1 str-buy-bullets
		vf := -1
		menu-add 0 str-not-interested
		menu
		if t0 == 0 then return
		sub BIG_BULLETS_PRICE PLAYER_CASH
		script script-buy-bullets
	end
;

: handle-mugging
	script script-begin-mugging
: handle-combat
	menu-clear
	i := long has-gun
	load v0
	i := long bullets-addr
	load v1 - v1
	if v1 == 0 then v0 := 0
	if v0 != 0 begin
		vf := v1
		menu-add 1 str-use-gun
		vf := -1
	end
	menu-add 2 str-flee
	menu-add 3 str-surrender
	menu
	if t0 == 1 begin
		script script-use-gun
		return
	end
	if t0 == 2 begin
		script script-flee
		return
	end
	fill-region item-owned 7 0
	script script-surrender
;

: handle-events
	i := long event-index
	load v0 - v0
	if v0 == 45 then jump handle-mugging # it's a hard-knock life...
	v0 += 1
	save v0 - v0
	i := long event-queue
	i += v0
	load v0
	v0 += v0
	jump0 event-dispatch-table
: event-dispatch-table
	jump handle-newsflash
	jump handle-unlock
	jump handle-arms-dealer
	jump handle-mugging
	jump handle-reward
	return

###########################################
#
#  Entrypoint
#
###########################################

to-data

: img-title
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x3F 0x00 0x3F 0x00 0x38 0x00 0x38 0x00 0x3F
	0x00 0x3F 0x00 0x38 0x00 0x38 0x00 0x3F 0x00 0x3F 0x00 0x3F 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x01 0x0F 0xF1 0x1F 0xF8 0x1C 0x39 0x1C 0x3B 0x1C 0x03 0x1C 0x03 0x1C 0x3B
	0x1C 0x3B 0x1F 0xFB 0x1F 0xFB 0x0F 0xF1 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0xE0 0x00 0xF0 0x00 0x77 0x77 0x77 0x77 0xE7 0x77
	0xF7 0x77 0x77 0x77 0x77 0x70 0xF7 0xF7 0xF7 0xF7 0xE3 0xF3 0x00 0x00 0x00 0x07
	0x00 0x03 0x00 0x03 0x00 0x05 0x00 0x0D 0x00 0x0E 0x00 0x1C 0x00 0x00 0x00 0xFE
	0x03 0xFF 0x0F 0xFF 0x1F 0xFF 0x3F 0xFF 0x7F 0xFF 0x7E 0x0F 0xF8 0x33 0xE0 0x3C
	0xE0 0x1C 0xC0 0x1D 0x00 0x01 0xF3 0xF3 0xFB 0xFB 0xBB 0xBB 0xBB 0xB9 0xBB 0xB9
	0xBB 0xB9 0xFB 0xB9 0xFB 0xB9 0xF3 0xB9 0x00 0x00 0x06 0x0F 0x03 0xFF 0x00 0xFE
	0x03 0x18 0x0C 0x06 0x3B 0x83 0x63 0x80 0x03 0x80 0xF0 0x3F 0xFB 0xBF 0x3B 0xBB
	0x83 0xBB 0xFB 0xBB 0x7B 0xBB 0x3B 0xBB 0xFB 0xBB 0xFB 0xBB 0x00 0x00 0xE0 0x00
	0xF8 0x03 0xE2 0x0F 0xDD 0xBF 0xDD 0xBF 0xDC 0x03 0x41 0xFD 0x1D 0xFE 0x1D 0xCE
	0x9D 0xE0 0xDD 0xFE 0xDC 0x1E 0xDD 0xCE 0xDD 0xFE 0xDC 0xFE 0xC0 0x01 0xF6 0x0D
	0x0F 0x1E 0xDF 0xFF 0xC0 0x00 0xE7 0xE7 0xEF 0xEF 0xEE 0xEE 0xCE 0xEE 0xCE 0xEE
	0xCE 0xEE 0xCF 0xEF 0xCF 0xEF 0xC7 0xA7 0x00 0x00 0xE0 0x0F 0x80 0x0F 0x00 0x00
	0x00 0x00 0x00 0x00 0x80 0x00 0xC0 0x00 0x40 0x00 0x1F 0x3F 0xBF 0xBF 0xB1 0xB9
	0xBF 0xBC 0xBF 0xBF 0xB0 0x03 0xBF 0xB9 0xBF 0xBF 0x9F 0x9F 0x00 0x00 0xFC 0x00
	0xF8 0x00 0xF8 0x00 0xF4 0x00 0xF6 0x00 0xEE 0x00 0xC7 0x00 0x80 0x00 0x0F 0xE0
	0xBF 0xF8 0xFF 0xFE 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFE 0x0F 0xF9 0x83 0xE1 0x80
	0xEE 0x00 0x0E 0x00 0x0E 0x00 0xC0 0x7C 0xEE 0xFE 0xEE 0xEE 0xEE 0xEE 0xEE 0xEE
	0xEE 0xEE 0xEE 0xFE 0xEE 0xFE 0xEE 0x7C 0xE0 0x00 0xEE 0x0C 0xDF 0xF8 0x0F 0xE0
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x9F 0xC0 0xDF 0xE0 0xDC 0xE0
	0x1E 0x00 0xDF 0xE0 0xC1 0xE0 0xDC 0xE0 0xDF 0xE0 0xCF 0xE0 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x00 0xC0 0x00 0xC0 0x00 0xE0 0x00 0xE0 0x00
	0xF0 0x00 0x70 0x00 0x00 0x00 0xEE 0xFE 0xEE 0xFF 0xEE 0xE7 0xEE 0xF0 0xEE 0xFF
	0xEE 0x0F 0xFE 0xE7 0xFE 0xFF 0x7E 0x7F 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
	0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

: script-intro
	s-clear
	s-blit img-title
	s-pause
	s-end

: str-inventory 0x08 0x27 0x2F 0x1E 0x27 0x2D 0x28 0x2B 0x32 0xFF
: str-tips      0x13 0x22 0x29 0x2C 0xFF 
: str-finish    0x05 0x22 0x27 0x22 0x2C 0x21 0xFF 
: str-escape    0x04 0x2C 0x1C 0x1A 0x29 0x1E 0xFF
: str-loans     0x0B 0x28 0x1A 0x27 0x2C 0xFF
: str-gamble    0x06 0x1A 0x26 0x1B 0x25 0x1E 0xFF
: str-raid      0x11 0x1A 0x22 0x1D 0xFF
: str-soldfor   0xFE 0x20 0x10 0xFB 0xF9 0xFE 0x20 0x19 0x2C 0x28 0x25 0x1D 0xF9 0x1F 0x28 0x2B 0xFF # $0

: zone-actions-table # [str-lo, str-hi], key
	pointer str-escape 1 # 0 - docks
	pointer str-raid   2 # 1 - eastside (hospitals)
	pointer str-raid   2 # 2 - the wall (FEMA camp)
	pointer str-raid   2 # 3 - university park (chemistry lab)
	pointer str-gamble 3 # 4 - broadway (casino)
	pointer str-raid   2 # 5 - west side (markets)
	pointer str-loans  4 # 6 - city core

to-code

:macro check-death {
	i := long player-injury
	load v0
	if v0 >= MAX_DAMAGE then jump death-injury
}

: handle-dispatch
	jump end-misc-actions # 0
	jump handle-escape    # 1
	jump handle-raid      # 2
	jump handle-gamble    # 3
	jump handle-loans     # 4
	jump handle-inventory # 5
	jump handle-tips      # 6

: main
	nokia-init
: game-start
	init-world
	script script-intro
	loop
		show-homescreen
		churn-economy
		dialog-pause

		i := long game-zone
		load v2 - v2
		i := long place-title-table
		i += v2
		i += v2
		load v1
		clear
		print-text
		dialog-pause

		i := long place-shown-desc
		i += v2
		load v0 - v0
		if v0 == 0 begin
			v0 := 1
			save v0 - v0
			i := long place-desc-table
			i += v2
			i += v2
			load v1
			clear
			print-text
			dialog-pause
		end

		# selling
		menu-clear
		menu-verb verb-sell
		t0 := 0
		t1 := 0
		loop
			i := long item-owned
			i += t0
			load v0
			t1 |= v0 # do we have any items at all?
			if v0 != 0 begin
				i := long item-name-table
				i += t0
				i += t0
				load v1
				ve := t0
				t0-item-price
				menu-add-body
			end
			t0 += 1
			if t0 != ITEM_TYPES then
		again
		vf := -1
		menu-add 0xFF str-nothing
		if t1 != 0 begin
			# only consider selling if the player
			# actually has items in their inventory.
			vd := 1
			menu
			if t0 != 0xFF begin
				t0-item-price
				decode vf

				i := long item-owned
				i += t0
				load t1 - t1
				vf := 0
				save vf - vf
				copy BIG_ZERO BIG_TEMP
				loop
					while t1 != 0
					add BIG_DECODE BIG_TEMP
					t1 += -1
				again
				add BIG_TEMP PLAYER_CASH

				# display sales figures:
				i := long item-name-table
				i += t0
				i += t0
				load v1
				i := long print-string0-read
				save v1
				clear
				print str-soldfor
				cursor-x := 98
				cursor-y := 40
				unpack16 BIG_TEMP
				currency-nokia
				dialog-pause
			end
		end

		: misc-actions
		menu-clear
		menu-add 5 str-inventory
		menu-add 6 str-tips
		i := long game-zone
		load t0 - t0
		i := long zone-actions-table
		i += t0
		i += t0
		i += t0
		load v2
		ve := v2
		menu-add-body			
		menu-add 0 str-finish
		menu
		v0 <<= t0
		jump0 handle-dispatch
		: end-misc-actions

		check-death

		# buying
		menu-clear
		menu-verb verb-buy
		t0 := 0
		loop
			i := long item-unlocked
			i += t0
			load v0
			if v0 != 0 begin
				i := long item-name-table
				i += t0
				i += t0
				load v1
				ve := t0
				t0-item-price
				menu-add-body
			end
			t0 += 1
			if t0 != ITEM_TYPES then
		again
		vf := -1
		menu-add 0xFF str-nothing
		vd := 1
		menu
		if t0 != 0xFF then quantity

		# travel destination
		: travel
		menu-clear
		menu-verb verb-travel
		i := long game-zone
		load t1 - t1
		t0 := 0
		loop
			i := long place-adj-table
			i += t1
			i += t1
			i += t1
			i += t0
			load ve - ve
			i := long place-name-table
			i += ve
			i += ve
			load v1
			menu-add-body
			t0 += 1
			if t0 != 3 then
		again
		menu
		i := long game-zone
		save t0 - t0

		handle-events
		handle-goons
		check-death
	again
